Node.js + Nginx – What now?

Nginx works as a front end server, which in this case proxies the requests to a node.js server. Therefore you need to setup an nginx config file for node. This is what I have done in my Ubuntu box: Create the file yourdomain.com at /etc/nginx/sites-available/: In it you should have something like: If you want nginx (>= 1.3.13) … Read more

Enabling HTTPS on express.js

In express.js (since version 3) you should use that syntax: In that way you provide express middleware to the native http/https server If you want your app running on ports below 1024, you will need to use sudo command (not recommended) or use a reverse proxy (e.g. nginx, haproxy).

Unable to connect to mongolab, Getting MongoError: auth failed

Make sure you are using the database username and password not the account username and password from Mlab. In MLab, formerly MongoLab, do the following Navigate to Users Add Database User Choose your username and password Now you can test this on the shell with mongo ds061374.mlab.com:61374/yourdb -u <dbuser> -p <dbpassword>

Mongoose: CastError: Cast to ObjectId failed for value “[object Object]” at path “_id”

Short answer: use mongoose.Types.ObjectId. Mongoose (but not mongo) can accept object Ids as strings and “cast” them properly for you, so just use: However, the caveat is if req.params.id is not a valid format for a mongo ID string, that will throw an exception which you must catch. So the main confusing thing to understand is that mongoose.SchemaTypes has stuff … Read more

NodeJS w/Express Error: Cannot GET /

You typically want to render templates like this: However you can also deliver static content – to do so use: Now everything in the /public directory of your project will be delivered as static content at the root of your site e.g. if you place default.htm in the public folder if will be available by visiting /default.htm Take a look … Read more

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