get client ip address in express.js

According to this, do following to determine the client ipaddress:

1
2
3
4
var ip = (req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress).split(",")[0];

Using setter in Mongoose

According to mongoose.js doc, it is able to set setters to a field on schema.
However, the doc is not quite detailed and obselete.
Some example:

1
2
3
4
5
6
7
8
9
10
11
var schema=new Schema({
password:{
type:String,
required:true,
set:hash
}
})

function hash(plainPwd){
return require("crypto").createHash("sha1").update(plainPwd).update(secret).digest("hex");
}

minimist: a neat cli argv parser

minimist is a lightweight cli argument (command line arguments) parser:

1
2
3
4
5
6
7
8
9
10
11
require('minimist')("-x 3 -y 4 -n5 -abc --beep=boop foo bar baz");

//output:
{ _: [ 'foo', 'bar', 'baz' ],
x: 3,
y: 4,
n: 5,
a: true,
b: true,
c: true,
beep: 'boop' }