본문 바로가기
Web/Etc

[Node] NPM (Node Package Manager)

by llHoYall 2020. 8. 30.

npm is a package manager for the JavaScript programming language.

It also helps to manage the project.

Project Initialization

Initialize a proejct

$ npm init
$ npm init -y

It will create the package.json file.

If run the command with -y option, it creates the default settings. If not, it creates with interactive mode.

Description

  • name: Project name
    • Should be less than 214 characters
    • Don't start with .(dot) or -(dash or hyphen).
    • Don't use the upper case character
  • version: Project version
  • description: Project description
  • main: Entry point
  • scripts: Project commands
  • author: Project author
  • dependencies: Project dependent packages
  • devDependenties: Project dependent packages for developing only
  • keywords: Proejct keywords
    • Used for searching
  • homepage: The URL to the project homepage
  • bugs: Project issue and bug tracking
    • url: The URL for an issue or bug tracking
    • email: An email for an issue or bug tracking
  • license: The license that the project follows

Usage

Run project scripts

Execute command specified in scripts field within package.json.

$ npm run-script <command>

Aliased as run, rum, urn.

 

Some commands such as start can omit run-script.

Package installation

$ npm install [--save-dev (-D) | --global (-g)] [package]

Aliased as i, isntall, add.

 

npm install command installs specified packages in dependencies and devDependencies field within package.json.

If you add --save-dev (-D) option, packages are installed in development mode.

If you add --global (-g) option, packages are installed in globally.

It can be needed Python.
It can be needed Windows Build Tools.
  $ npm install windows-build-tools

Show installed package list

$ npm ls [--global (-g)]

Aliased as list, la, ll.

 

If you want to show brief list without dependencies, run this command.

$ npm ls -g --depth 0

'Web > Etc' 카테고리의 다른 글

[Babel] Getting Started  (0) 2020.09.10
[Pug] Getting Started  (0) 2020.09.09
[Node] yarn  (0) 2020.08.30
[Node] Node.js  (0) 2020.08.30
[Node] NVM (Node Version Manager)  (0) 2020.08.30

댓글