npmã®åºæ¬çãªä½¿ãæ¹ã¾ã¨ã
npmã®åºæ¬çãªä½¿ãæ¹ã®ã¾ã¨ãã§ããå¿ããã¨ãã«è¦è¿ãç¨ã
- npmã®ã¤ã³ã¹ãã¼ã«ãããã¢ã¸ã¥ã¼ã«ãåã£ã¦ãã¦ä½¿ãã¨ããã¾ã§ã
- ç°å¢ã¯ãCentOS7ã§ãã
ã¤ã³ã¹ãã¼ã«
node.jsãã¤ã³ã¹ãã¼ã«ããã¨ãä¸ç·ã«å
¥ãã¾ãã
ここãåèã«ã½ã¼ã¹ããã¤ã³ã¹ãã¼ã«ãã¾ããã
$ sudo yum groupinstall 'Development tools' $ wget http://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz $ tar xvf node-v0.12.0.tar.gz $ cd node-v0.12.0/ $ ./configure --prefix=/usr/local $ make $ sudo make install
ãã¼ã¸ã§ã³ã確èªã
$ node -v v0.12.0 $ npm -v 2.5.1
ã¢ã¸ã¥ã¼ã«ã®ã¤ã³ã¹ãã¼ã«
$ npm install <ã¢ã¸ã¥ã¼ã«å> ä¾) $ npm install gulp
- ã¢ã¸ã¥ã¼ã«åãæå®ããªãå ´åãpackage.json ã«æ¸ãããä¾åã¢ã¸ã¥ã¼ã«ãã¤ã³ã¹ãã¼ã«ãã¾ãã
- <ã¢ã¸ã¥ã¼ã«å>@<ãã¼ã¸ã§ã³> ã§ä»»æã®ãã¼ã¸ã§ã³ã®ã¢ã¸ã¥ã¼ã«ãã¤ã³ã¹ãã¼ã«ã§ãã¾ãã
- åè:npm - CLI Commands - install
ãã¼ã«ã«ã¤ã³ã¹ãã¼ã«ã¨ã°ãã¼ãã«ã¤ã³ã¹ãã¼ã«
- ãã¼ã«ã«ã¤ã³ã¹ãã¼ã«
- éçºä¸ã®ã¢ããªãä¾åããã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ããå ´åã«å©ç¨ãã¾ãã
- ã¤ã³ã¹ãã¼ã«ããã¢ã¸ã¥ã¼ã«ã¯ãããã¸ã§ã¯ãå
ã®ã¿ã§ä½¿ãã¾ãã
- åããã·ã³ã§éçºãã¦ããä»ã®ããã¸ã§ã¯ãããã¯ä½¿ããªãã®ã§ãããããã§å¥ã®ãã¼ã¸ã§ã³ã使ç¨ãããã§ãã¾ãã
- ã¢ã¸ã¥ã¼ã«ã¯ã
/node_modules ã«ã¤ã³ã¹ãã¼ã«ããã¾ãã
- ã°ãã¼ãã«ã¤ã³ã¹ãã¼ã«
- grunt ã®ãããªããã·ã³å ¨ä½ã§å ±æã§ãããã¼ã«ãã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ããå ´åã¯ãã¡ãã
- ã¤ã³ã¹ãã¼ã«ããã¢ã¸ã¥ã¼ã«ã¯ããã·ã³å
¨ä½ã§å
±æããã¾ãã
- 試ããç°å¢ã§ã¯ã --prefix=/usr/local ãæå®ãã¦ã³ã³ãã¤ã«ãã¦ããã®ã§ãã¢ã¸ã¥ã¼ã«ã¯/usr/local/lib/node_modules/ ã«ã¤ã³ã¹ãã¼ã«ããã¾ããã
- ãã¼ããã·ã§ã³ã«æ³¨æãEACCES ã¨ã©ã¼ãèµ·ããå ´åã¯ãパーミッションか、インストール先を変更ãã¾ãã
試ãã«ãgulp ãã¤ã³ã¹ãã¼ã«ãã¦ã¿ã¾ãã
- -gãã¤ããã¨ã°ãã¼ãã«ã¤ã³ã¹ãã¼ã«ã«ãªãã¾ãã
- ãã¼ã¸ã§ã³ãæ示ãã¦ãããããå¥ãã¼ã¸ã§ã³ãã¤ã³ã¹ãã¼ã«ãã¦ã¿ã¾ãã
$ mkdir -p test/app $ cd test/app $ sudo npm install -g [email protected] $ gulp -v [09:55:35] CLI version 3.8.10 $ npm install [email protected] $ gulp -v [10:02:46] CLI version 3.8.10 [10:02:46] Local version 3.8.11
ã¤ã³ã¹ãã¼ã«ããã¢ã¸ã¥ã¼ã«ã使ã
require ãã¦ä½¿ãã¾ãã
以ä¸ã¯ã uuid ãã¤ã³ã¹ãã¼ã«ãã¦uuidãåºåãããµã³ãã«ã§ãã
ã¤ã³ã¹ãã¼ã«
$ npm install uuid
uuidã使ãããã°ã©ã test.js ãæ¸ãã¾ãã
"use strict"; var uuid = require('uuid'); console.log(uuid.v1());
å®è¡ãã¦ã¿ã¾ãã
$ node test.js 28bc71c0-c533-11e4-ad39-918ab091b1ed
ã¢ã¸ã¥ã¼ã«ã®ã¢ã³ã¤ã³ã¹ãã¼ã«
uninstallãå®è¡ããã°OK
$ npm uninstall uuid
ã¤ã³ã¹ãã¼ã«æ¸ã¿ã¢ã¸ã¥ã¼ã«ãä¸è¦§è¡¨ç¤ºãã
ls ã§ãã¼ã«ã«ã«ã¤ã³ã¹ãã¼ã«ããã¢ã¸ã¥ã¼ã«ã®ä¸è¦§ã表示ãã¾ãã
$ npm ls test/app ââ⬠[email protected] âãâââ [email protected] âãââ⬠[email protected] âãâãâââ [email protected] âãâãâââ [email protected] âãâãââ⬠[email protected] âãâãâãâââ [email protected] âãâãââ⬠[email protected] âãâãâãâââ [email protected] âãâãâââ [email protected] âãâââ [email protected] âãââ⬠[email protected] âãâãâââ [email protected] .. ç¥