Node development setup on Windows
Installing Node natively in Windows
There are a number of ways you can install Node natively in Windows, including:
- Using NVM for Windows (preferred for if you need the ability to switch between Node versions)
- Laravel Herd also includes Node and NVM[1].
- Using the Chocolatey package manager through PowerShell[2]
- Downloading and running the installer from nodejs.org (quickest and easiest in the short term, but not great for updates or switching between versions easily)
For ease of version management, using NVM for Windows (if you prefer the command line) or Laravel Herd (if
you prefer a GUI and are already using it for PHP and Composer) is recommended.
Warning
Unlike for PHP where you can have multiple instances from Chocolatey, Herd, Local, and other web server applications installed concurrently without issue, you can't use Herd to manage Node if you have NVM for Windows installed independently. (Not sure about Chocolatey.)
So if you have NVM but want to use Herd for Node version management now, you'll need to uninstall NVM first and then re-install it through the Herd UI.
In any case, once you've installed Node using your method of choice, all commands will be the same from there other than
upgrading or switching between versions.
Confirm that the node alias works in PowerShell (and check your version) like so:
node -v
If this doesn't work, you may need to manually add Node to your PATH system environment variable.
To check where PowerShell is loading Node from if you have multiple instances, you can use:
Get-Command node
Middle ground: Using Windows' Node in WSL
Like for Composer, after following the native installation instructions above you can use Windows' Node installation in WSL by creating aliases to Node and NPM in your Bash configuration file (.bashrc or .zshrc) like so:
# # /home/leesa/.zshrc
alias node='/mnt/c/Program\ Files/nodejs/node.exe'
alias npm='powershell.exe /c npm'
Restart the WSL terminal before trying to use these aliases.
Installing Node natively in WSL
You can also install Node directly in WSL using its own version of NVM.
PhpStorm's various configuration options that involve Node pick up WSL's Node instance as an option, so ensuring you're using the same instance across all tools is generally straightforward once Node is installed.
Step 1: Install NVM
Instructions for installing NVM on WSL can be found in:
Step 2: Install Node
Once you have NVM installed within WSL (not referring to Windows NVM here, if you have it), you can install any version of node using thenvm install command.
See Install and switch between different versions of Node below for more information.
Step 3: Confirm Node alias is available
Confirm that the node alias works in WSL (and check your version) like so:
node -v
:::
Install and switch between different versions of Node
These options are applicable to the following setups:
- NVM for Windows standalone installation
- Laravel Herd
- NVM in WSL
Install a new version:
nvm install lts/iron
nvm install lts/iron
Change to a different installed version (example):
nvm use lts/iron
nvm use lts/iron
You can also refer to versions using their numbers rather than codenames. More information about the latest Node versions and their aliases can be found at at https://nodejs.org/en/about/releases/.
Optional PhpStorm Configuration
See the PhpStorm configuration notes for more information on configuring Node in PhpStorm.
Herd is a good option if you don't have any pre-existing stuff that might conflict, or are happy to use it for all Node management in Windows. ↩︎
Chocolatey is great for a lot of things, but I wouldn't recommend it for Node unless you don't expect to ever need to switch between Node versions easily. ↩︎
