Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Last active February 7, 2024 19:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save peteristhegreat/846d9420684f7d0504039615cc45b704 to your computer and use it in GitHub Desktop.
Save peteristhegreat/846d9420684f7d0504039615cc45b704 to your computer and use it in GitHub Desktop.
NVM Windows, NodeJS, VSCode, Instructions

Nice to haves for the command prompt

pmify.com/choco

chocolatey => choco
clink => bash readline and history baked into CMD
gow => ls, grep and other nice bash tools aka "GNU on Windows"

Install with Chocolatey

choco install gow clink-maintained

Getting node and nvm and npm and yarn working on a Windows computer is not trivial.

Here are the basics for getting a good setup:

Install NVM for windows

https://github.com/coreybutler/nvm-windows

Go to releases, and download one of the setup.zips

It will make a file in %appdata%/nvm

Add that new folder into your path!

Now in a new command prompt install a version of node.

nvm install 14.16.0

nvm use v14.16.0

Now you have in your C:/Program Files/nodejs a link to your %appdata%/nvm/v14.16.0

Add that Program Files folder to your path C:/Program Files/nodejs .

Now you have NodeJs on Windows.

Note: Whenever you change your path you need to restart your command prompt, or VSCode to be able to find it.

Now go into a fresh command prompt and run:

node
> console.log("Hello World");

You Win. Congrats. GG EZ.

https://code.visualstudio.com/docs/nodejs/nodejs-tutorial

VSCode Live Server Extension

Click the legos icon on the left. Search for Live Server. Install it.

Download the public folder in this project:

https://github.com/processing/p5.js/wiki/Local-server#node-http-server

Right click on index.html inside VSCode and run with Open with Live Server

And you win again!

Get clink to work in VSCode

https://stackoverflow.com/a/43363255/999943

Down the node rabbit hole

Fix Powershell script policy

https://www.faqforge.com/windows/windows-powershell-running-scripts-is-disabled-on-this-system/

In an admin command prompt... run set-executionpolicy remotesigned

C:\Users\peter\AppData\Roaming>powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\peter\AppData\Roaming> set-executionpolicy remotesigned

Install Yarn and some other globals

npm install --global yarn

# never run npm again, use yarn

Make a project using Processing.js aka p5.js

https://p5js.org/get-started/ down at the section Setting up p5.js with an editor on your own computer

https://github.com/processing/p5.js/wiki/Local-server#node-http-server

This is the version I am recommending.

yarn global add http-server
yarn global add browser-sync

Note yarn global add puts it in C:/Users/username/.node_modules and just yarn add puts it in ./project_folder/.node_modules

Setting up p5.js

https://github.com/nishanc/p5js-server

git clone https://github.com/nishanc/p5js-server my-project

Make my-project the project folder in vscode. (close the folder, and then open the new folder)

Go to Terminal > New Terminal

Now follow the README.md

yarn install
node server             #  Note: same as node server.js

Now edit public/sketch.js. Save the file and open localhost:3000 in Chrome.

Mix in some browser sync magic

https://stackoverflow.com/questions/37548537/express-and-browsersync-without-gulp

node server & browser-sync start --proxy 'localhost:3000' --files 'public'

But ampersand doesn't work in Windows...

https://stackoverflow.com/questions/185575/powershell-equivalent-of-bash-ampersand-for-forking-running-background-proce

# snake game fix for browser:
```
function keyPressed() {
switch (keyCode) {
case 37:
if (direction !== 'right') {
direction = 'left';
}
break;
case 39:
if (direction !== 'left') {
direction = 'right';
}
break;
case 38:
if (direction !== 'down') {
direction = 'up';
}
break;
case 40:
if (direction !== 'up') {
direction = 'down';
}
break;
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment