This article explains how to install Node.js on Windows.
Reference URLs
1. DOWNLOAD THE FILE
Although v12 is an older version, it is still covered by Long-term Support.
Node versions change rapidly, but even-numbered versions are LTS and are supported for a longer period.
Odd-numbered versions have shorter support periods. For example, v14 is supported until 2023-4-30, while the next version, v15, is only supported until 2021-6-1.
It's good practice to include Node.js version management, but we'll omit it this time.
Double-click the downloaded file to start the installation.
2. CHECK WITH COMMAND PROMPT
After installing Node.js, a shortcut named 'Node.js command prompt' will also be created inside the node folder.
node -vIf you enter the above command and the Node version appears, it means the installation was successful.
npm -vRunning this command allows you to check the version of npm, which controls Node.js packages.
3. HOW TO USE NPM
You can install various Node.js packages.
By sharing package.json, developers can also share their development environments.
Initialize npm to use it in the current directory. A `package.json` file will be generated.
npm init -yYou can install a specified 'package name' in the current directory using the following command.
npm install <package-name>c:\project\test>If the above is displayed, it means the package will be installed inside the `test` directory.
// package.json
{
"name": "test",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"keywords": [],
"description": ""
}"keywords": [
"node",
"javascript",
"express"
],Installing Packages
npm install <package-name>Executing the above command allows you to install the specified 'package name'.
--save Adds to dependencies in package.json
--save-dev Adds to devDependencies in package.json
-g Installs globally in the local environmentnpm install express --saveWhen you install a package, it is added to `package.json`.
Refer to the following example for packages. They are listed under `dependencies` and `devDependencies`.
{
"name": "test",
"version": "1.0.0",
"dependencies": {
"express": "^4.13.3"
},
"devDependencies" : {
"gulp": "^3.8.10"
}
}・dependencies: Applications required for the production version.
・devDependencies: Applications used only in the development environment.
Uninstalling Packages
npm uninstall <package-name>To also remove it from `package.json`, run the command with `--save`.
Updating Packages
npm install <package-name>Running `npm install <package-name>` again for an already installed package will update it.
npm updateThis command updates all installed packages.
npm outdated --depth=0To Update npm Itself
To update npm itself, you also use `install`. In some cases, you might need administrator privileges for this (right-click 'Command Prompt' and select 'Run as administrator').
npm install npm@latest -gThis has been a brief introduction to installing Node.js and npm.
node sample.jsYou can run files like this. I don't use it very often, but it's good to know for reference.
📦