Node.js app in the real world : deployment, decorators, going further
This is Part 5 of a 5-part series.
Part 0 was the introduction, Part 1 was about structuring your application and coding style, Part 2 was about persisting our domain, setting up the HTTP interface. Part 3 was about authentication, access control and error handling. Part 4 was about CLI commands, commenting, documenting and testing our REST API written in JavaScript under Node.js with a Koa server, a Mongodb database and the Mongoose ODM. This final part will be about deploying and some “advanced” tips and tricks.
How to deploy in production ?
Configuration files
Before deploying in production, you have to differentiate your dev, test and prod environnements. One way to do it is to have the following structure :
config/
environments/
dev.js
prod.js
test.js
app.js
db.js
cache.js
index.js
In your database configuration file, you’ll have something like this :
config/db.js
const dbConfig = {
dev: {
host: ‘localhost’,
port: ‘27017’,
database: ‘myApp_dev’,
auth: false
},
test: {
host: ‘localhost’,
port: ‘27017’,
database: ‘myApp_test’,
auth: false
},
prod…