NodeJS

  • nodejs can handle more than 1M concurrent connections in a 16GB server study and over 600k websocket connections.

Best Practices

Graceful shutdown for your applications

When you deploy a new version of your application, the old must be replaced. The process manager you are using (no matter if it is Heroku, Kubernetes, supervisor or anything else) will first send a SIGTERM signal to the application to let it know, that it is going to be killed.

Once it gets this signal, it should:

  • stop accepting new requests
  • finish all the ongoing requests
  • and clean up database connections or file locks.

terminus is an npm package to help gracefully shutdown nodeJS apps.

Standards

http://node-machine.org/

Website indicators

Compression

  1. /**
  2. * GZip helper
  3. * To use this, the build has to compress the bundles into gzip.
  4. * @return {undefined}
  5. */
  6. sendGzip (req, res) {
  7. let filePath = path.resolve(`public/${req.path}`);
  8. if (/css/.test(filePath)) {
  9. res.setHeader('Content-Type', 'text/css');
  10. }
  11. if (!fs.existsSync(filePath)) {
  12. res.setHeader('Content-Encoding', 'gzip');
  13. filePath += '.gz';
  14. }
  15. res.sendFile(filePath);
  16. }
  17. // or use `npm compression`
  18. import compress from 'compression';
  19. app.use(compress());
  • vim: associate .hbs file extension with HTML by adding the line au BufNewFile, BufRead *.hbs set file type=html to your .vimrc file

Page tests

HTTP

  • HTTP ports use 1023+ (pg 54)
  • HTTP queryStrings must be URL encoded (eg. using encodeURIComponent
  • URL hash (fragment) # is only in the browser (eg. `id=’chapter-03’)

Tools