设置淘宝源
npm config set registry https://registry.npm.taobao.org
检查确认
cat ~/.npmrc registry=https://registry.npm.taobao.org
设置淘宝源
npm config set registry https://registry.npm.taobao.org
检查确认
cat ~/.npmrc registry=https://registry.npm.taobao.org
➜ ~ node
> var a = 1;
undefined
> typeof a
'number'
> var b = {}
undefined
> typeof b
'object'
> var c = function() {};
undefined
> typeof c
'function'
> var d = '';
undefined
> typeof d
'string'
遇到过 forever 装不上的情况
/usr/bin/npm install forever -g 701 error Error: shasum check failed for /root/tmp/npm-5826-Ev6S_4GZ/1438247556786-0.7053809177596122/tmp.tgz 701 error Expected: 4353b88b7131797fb5520e39eba263df5863cba3 701 error Actual: 28322c7853c55e33081b19337d4e5359b8cceaae 701 error at /usr/lib/node_modules/sha/index.js:38:8
换成淘宝的registry后正常。
npm config set registry http://registry.npm.taobao.org/
node.js的forever可保证进程挂掉之后重启,保证高可用
Monitors the script specified in the current process or as a daemon
[Daemon]
The forever process will run as a daemon which will make the target process start
in the background. This is extremely useful for remote starting simple node.js scripts
without using nohup. It is recommended to run start with -o -l, & -e.
ex. forever start -l forever.log -o out.log -e err.log my-daemon.js
常用动作有
start Start SCRIPT as a daemon
stop Stop the daemon SCRIPT
stopall Stop all running forever scripts
restart Restart the daemon SCRIPT
restartall Restart all running forever scripts
list List all running forever scripts
config Lists all forever user configuration
set Sets the specified forever config
clear Clears the specified forever config
logs Lists log files for all forever processes
logs <script|index> Tails the logs for <script|index>
columns add
Adds the specified column to the output in `forever list`
columns rm
Removed the specified column from the output in `forever list`
columns set Set all columns for the output in `forever list`
columns reset Resets all columns to defaults for the output in `forever list`
cleanlogs [CAREFUL] Deletes all historical forever log files
例子:
查看被forever启动的进程
forever list
重启具体某一个脚本,如果不知道绝对路径,forever会自动匹配重启
forever restart myscript.js
–sourceDir指定js脚本位置
forever stop --sourceDir=/data/nodejs/ start.js
-l 指定log所在位置, -e 指定错误日志,-o指console的输出,-a 追加的方式,平时使用时最好把-l, -e, -o全用上。
forever start -l /var/log/nodejs/log -e /var/log/nodejs/error -o /var/log/nodejs/out.log -a --sourceDir=/data/nodejs start.js
安装nodejs,npm
apt-get install nodejs apt-get install npm
编写hello.js
var http = require('http');
http.createServer(
function(req, res){
res.writeHead(200, {'Content-Type':'text/plain'});
res.end('hello node.js');
}
).listen(8124,"127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
运行
node hello.js
打开浏览器即可看到
hello node.js