Nodejs
Node.js 10 Best Practices to Start Right Now
Read more about these individual tips at Sitepoint article .
- Use npm scriptsStop writing bash scripts when you can organize them better with npm scripts and Node. E.g., npm run build, start and test. npm scripts are like the single source of truth when Node developers look at a new project.
- Use env varsUtilize process.env.NODE_ENV by setting it to development, or production. Some frameworks will use this variable too, so play by the convention.
- Understand the event loopsetImmediate() is not immediate while nextTick() is not next. Use setImmediate() or setTimeout() to offload CPU intensive tasks to the next event loop cycle.
- Use functional inheritanceAvoid getting into mindless debates and a brain draining trap of debugging and understanding prototypal inheritance or classes. Instead use functional inheritance.
- Name things appropriatelyGive meaningful names which will serve as a documentation. Also, please no uppercase filenames, use a dash if needed. Uppercase in filenames not just look strange but can cause cross platform issues.
- Consider NOT Using JavaScriptES6/7 is pathetic addition which was born out of 6 years of meetings when we already had a better JavaScript called CoffeeScript. Use it if you want ship code faster and stop wasting time debating var/const/let, semi colons, class and other arguments.
- Provide native codeWhen using transpilers, commit native JS code (result of the builds) so your projects can run without the builds
- Use gzipDuh! npm i compression S and sane logging not too much not to little depending on the environment. npm i morgan S
- Scale upStart thinking about clustering and having stateless services from day one of your Node development. Use pm2 or strongloop's cluster control
- Cache requestsGet maximum juice out of your Node servers by hiding them behind a static file server such as nginx and/or request level cache like Varnish Cache and CDN caching.
Read more about these individual tips at Sitepoint article.