add created_at and updated_at fields to mongoose schemas

UPDATE: (5 years later) Note: If you decide to use Kappa Architecture (Event Sourcing + CQRS), then you do not need updated date at all. Since your data is an immutable, append-only event log, you only ever need event created date. Similar to the Lambda Architecture, described below. Then your application state is a projection … Read more

Read a file in Node.js

Use path.join(__dirname, ‘/start.html’); var fs = require(‘fs’), path = require(‘path’), filePath = path.join(__dirname, ‘start.html’); fs.readFile(filePath, {encoding: ‘utf-8’}, function(err,data){ if (!err) { console.log(‘received data: ‘ + data); response.writeHead(200, {‘Content-Type’: ‘text/html’}); response.write(data); response.end(); } else { console.log(err); } }); Thanks to dc5.

NPM global install “cannot find module”

For anyone else running into this, I had this problem due to my npm installing into a location that’s not on my NODE_PATH. [root@uberneek ~]# which npm /opt/bin/npm [root@uberneek ~]# which node /opt/bin/node [root@uberneek ~]# echo $NODE_PATH My NODE_PATH was empty, and running npm install –global –verbose promised-io showed that it was installing into /opt/lib/node_modules/promised-io: … Read more

Error: unable to verify the first certificate in nodejs

unable to verify the first certificate The certificate chain is incomplete. It means that the webserver you are connecting to is misconfigured and did not include the intermediate certificate in the certificate chain it sent to you. Certificate chain It most likely looks as follows: Server certificate – stores a certificate signed by intermediate. Intermediate … Read more

How can I set the default timezone in node.js?

According to this google group thread, you can set the TZ environment variable before calling any date functions. Just tested it and it works. > process.env.TZ = ‘Europe/Amsterdam’ ‘Europe/Amsterdam’ > d = new Date() Sat, 24 Mar 2012 05:50:39 GMT > d.toLocaleTimeString() ’06:50:39′ > “”+d ‘Sat Mar 24 2012 06:50:39 GMT+0100 (CET)’ You can’t change … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)