Node.js deployment in production settings

While node.js is exciting, it is clear that it is not a solution for everything. In particular, it would be a very bad idea to use node.js for content management systems. It would take too much efforts to write a CMS based in Node.js from scratch comparing to other mature CMS in PHP/Java/.Net/Python. Personally, I also feel Node.js is not suited for the standard CRUD apps yet. There is no big frameworks built on top of Node.js which give you features such as ORM for multiple databases, code generation, security handling, user management and so on.

I also feel the Node modules system is very messy. There are many modules out there but each of them is doing their own way. We as the developers must go and plug all the pieces together. Ok, so now back to the point :)

Ideally our system can be separated into 2 parts:

1) the normal CRUD content parts (CMS, RSS, etc) and

2) the dynamic real time part (analytics, chat, real time updates, online collaboration, games)

The real time portion should be handled by Node.js while the normal part should be handled by PHP/Java or any of the more stable language with mature frameworks.

Here is some quick notes on Nodes deployment in production and integration with PHP:

1) use forever to auto restart Node.js in case the Node server crash

# install forever
$ [sudo] npm install forever -g

# turen on production variable and start the server app.js
# choose where to put the logs
$ NODE_ENV=production forever start -o ~/projects/out.log -e ~/projects/err.log app.js

# list out the apps
$ forever list

2) Use a common database for processes communication

Redis with publish/subscribe mechanism is a very good choice. It is a very fast memory store which can capture data posted by Node.js and then send it to PHP or vice versa. We can also store session information for common authentication.

3) Let PHP/Apache handle the static contents instead of node

4) For integration, we can run the node server separately from PHP/Apache. We just need to include the client library and connect to the server at the relevant port.

 <script src="/js/"></script>
        WEB_SOCKET_SWF_LOCATION = '/js/';

var socket = this.socket = io.connect('');
comments powered by Disqus