LoginSignup
151
171

More than 5 years have passed since last update.

npmコマンド覚え書き

Posted at

npm とは Node Package Manager の略で Node で 作られたパッケージモジュールを管理するためのツールです

1. npmのバージョンを確認する

$ npm -v
1.4.9

2.パッケージのインストールする

2.1.パケージのインストール(ローカル)

npm install package_name

2.2.パッケージのインストール(グローバル)

-gオプションを指定すると、グローバル領域にインストールされる。

npm install -g package_name

2.3.パッケージをインストールし、package.jsonへ書き込む

--saveオプションを指定して、package.jsonのdependenciesにバージョン付きで書き込む

npm install --save package_name

--save--devオプションを指定して、package.jsonのdevDependenciesにバージョン付きで書き込む
このオプションは開発時のみに利用するライブラリのバージョンを管理します。

npm install --save--dev package_name

2.4.グローバルインストールされたパッケージを確認する

$ npm ls -g
/Users/my_user/.nvm/v0.10.33/lib
├─┬ coffee-script@1.8.0
│ └── mkdirp@0.3.5
├─┬ express@4.10.2
│ ├─┬ accepts@1.1.3
│ │ ├─┬ mime-types@2.0.3
(略)
├─┬ js2coffee@0.3.3
│ ├─┬ coffee-script@1.7.1
│ │ └── mkdirp@0.3.5
│ ├── file@0.2.2
│ ├─┬ nopt@3.0.1
│ │ └── abbrev@1.0.5
│ └── underscore@1.6.0
└─┬ npm@1.4.28
  ├── abbrev@1.0.5
(略)

2.5.対話形式でプロジェクトの初期設定を行う

対話形式で項目を週力してpackage.jsonを作成する。

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (sample) sample
version: (1.0.0) 
description: log4js sample project.
entry point: (index.js) app.js
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /Users/my_user/Development/node.js/sample/package.json:

{
  "name": "sample",
  "version": "1.0.0",
  "description": "sample project.",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this ok? (yes) yes
151
171
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
151
171