Software engineering notes

Node.js

Install node.js & npm (package manager) & nvm (version manager)

Ubuntu

sudo apt-get update
sudo apt-get install nodejs nodejs-legacy
sudo apt-get install npm
git clone git://github.com/creationix/nvm.git ~/.nvm
. ~/.nvm/nvm.sh

Add path to .bashrc

echo ". ~/.nvm/nvm.sh" >> ~/.bashrc

Amazon Linux

(?) sudo yum install gcc-c++ make
sudo yum install nodejs npm --enablerepo=epel

Websocket example

npm install websocket -gd

test.js :

var sys = require("sys"),
my_http = require("http");
my_http.createServer(function(request,response){
    sys.puts("I got kicked");
    response.writeHeader(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
}).listen(9090);
sys.puts("Server Running on 9090");

Execute : node test.js Browser : http://192.168.56.1:9090/

redis

install :

npm install redis -gd

SAVE OR BGSAVE 指令, 快照儲存的路徑 : /var/lib/redis/dump.rdb

Install express web framework :

npm install express -gd
npm install -g express-generator
npm install -g ejs

Use (example: test):

express test --ejs
cd test
npm install          (install dependencies)
npm start

Install nodemon

檔案變動不用再重新啟動 node.js

安裝

npm install nodemon -g

啟動

cd test
nodemon ./bin/www

修改 `test/package.json` 將 `node ./bin/www` 改成 `nodemon ./bin/www`

ref

Packages

jshint : 檢查語法錯誤

npm install jshint -g

log.io

一個現成的套件提供介面看 log

建議安裝使用 root 安裝,比較不會遇到其他的麻煩 sudo npm install -g log.io --user="root"