nodejs

npm

命令

1
2
3
4
5
# 保存到当前项目
npm install -save koajs
# 全局命令
npm install -g koajs
# update|uninstall|list|search|init

设置某一次安装源

1
npm install -g npm --registry=https://registry.npm.taobao.org

安装cnpm

1
npm install --registry=http://r.cnpmjs.org -g cnpm

更新最新版本nodejs

1
2
3
4
sudo npm install -g n
n latest
# n 8.9 更新到8.9版本
# n rm 8.9 删除指定nodejs版本

nodejs chrome调试工具 node-inspector

1
2
3
4
5
6
7
8
9
10
11
#安装

npm install -g node-inspector

#启动app

node --debug=12345 index.js

#新命令行窗口开启调试

node-inspector --web-port 4000 --debug-port 12345

子进程

1
2
3
4
5
6
7
let cp=require('child_process')
let curdir = '/opt/do/hexo'
let cmd1 = `cd ${curdir};`
let cmd2 = `git pull;`
cp.exec(cmd1 + cmd2, function(err,stdout){
console.log(stdout)
})