Node.js Developers |
The best practices for Node.js developers
1. The developers practice test driven development. This is always important to combine few of the best practices for asset-packing, authentication, error handling etc.
2. Consider some of these generic suggestions for your work development:
• Use something RPC-based like NowJS, dnode, etc. for real time webapps.
• To restart your server when you make any changes to a file, you can use nodemon.
• To log exceptions and get detailed instant notifications, you can use Airbrake.
• To combine server logs from multiple machines, use Loggly.
• You can separate your configuration setting into a config file and use different settings for Production & Development environments.
• Append a GET parameter hash of the contents when serving static files.
• You can avoid static file service from node and use a CDN for bigger projects.
• Version your static files so that the file path is automatically updated when the file is updated, which will prevent polluted cache in browsers and proxies.
• You can use PaaS provider such as Nodejitsu, Modulus, etc- unless you really love being a system admin.
4. Forever: you can use it for long running processes like servers and workers, especially to handle auto-restarting processes running in production.
6. Some of the startup practices for Node.js developers are:
• You can start your project with npminit.
• You must always specify start and test command.
• You must save developer dependence in your package file.
• Divide codes in modules and use module.exports instead of exports.
• You must write codes by following any design pattern (Observer, Singleton, Factory etc.).
• To specify development stage, you must use Node.js process environment variable.
• When you make changes, use nodeman to restart your server.
• Follow standard coding guidelines such as casing, variable declaration.
Best practices for Node.js in production environments are not much different from best practices while using node in general. The main start of your project should be with npminit and use nodemon if you restart your server by changing files. Similarly, there are many other practices that are most important to be considered by a Node.js developer’s right time.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.