[Node.js]how to install node.js and use npm

Describes the installation of Node.js on Windows. Reference URL ⇒Node.js Home Page ⇒Keep npm up to date 1. Download the file ⇒Node.js Home Page Go to this page and download it. 2020.5.20 is currently v12.16.3 LTS v14.3.0 Current can be downloaded. v12 is an older version, but it is subject to Long-term Support. Node is […]

Describes the installation of Node.js on Windows.

Reference URL

Node.js Home Page
Keep npm up to date

1. Download the file

Node.js Home Page
Go to this page and download it.

2020.5.20 is currently
v12.16.3 LTS
v14.3.0 Current
can be downloaded.
v12 is an older version, but it is subject to Long-term Support.
Node is fast to change versions, but LTS versions are long supported by.
Odd versions are short support.For example, v14 is supported until 2023-4-30, but the next v15 is up to 2021-6-1.
For details, please refer to the following URL
node.js Releases

Node.js version control and also i hope to put it, but this time I'll spare.
Double-click the downloaded file to start the installation.
You are now ready to use node.js.

2.Check by command prompt

Windows command prompt.
You can also install node.js to get a shortcut called "node.js command prompt" in the node folder.

node -v

If you enter the above on the command, you can check the version of the node is installed.

npm-v

And you can also check the npm version that controls the node.js package.

3. How to use npm

You can install various packages of node.js.
Developers can also share their environments by sharing package.json.

Here's a simple command.

Initializes npm so that it can be used in the current directory.package.json is generated.

npm init -y

You can install "Package Name" in the current directory below.

npm install packageName

example) the command prompt is

c:/project/test>

installed in 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": ""
}

Rewrite it as needed.for example, such as keywords.

  "keywords": [
    "node",
    "javascript",
    "express"
  ],

Installing packages

npm install packageName

You can install the "package name" by running the above.
Optionally

--save      Add to dependencies in package.json
--save-dev  Add to devDependencies in package.json
-g          Install ing local environment globally

–save example)

npm install express --save

When you install a package, it is added to package.json.
The package should look at the following example.[dependencies]and[devDependencies] is listed in.

{
  "name": "test",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.13.3"
  },
  "devDependencies": {
    "gulp": "^3.8.10"
  }
}
  • dependencies: Applications needed for retail versions
  • devDependencies: Applications used only in the development environment

Uninstall packages

npm uninstall packageName

Use it if you want to uninstall (remove) the package.
If you want to remove it from package.json、add “– save”
If you want to remove it from global, add “-g”.

Package Updates

npm install packageName

If you install a packageName that is already installed again, the package is updated.

npm update

Update all installed packages.

npm outdated --depth=0

Shows the package where the update resides.

If you want to update npm itself

Npm update also uses install.In this case, you may need to enter with administrative rights.(Right-click "Run as Administrator" at command prompt startup

npm install npm@latest -g

If you run the above, the latest version will be installed.

I was introduced roughly how to install node.js and npm.

By the way if node.js runs on command

node sample.js

You can run in a feeling that.I don't use much, but until it's helpful.