Unfortunately, the standard site for searching N P M packages doesn’t work very well. Instead, use N P M S dot I O to screen packages for security, stability, quality, and current maintenance. There are many curated lists of N P M packages and resources. One good list, awesome dash node j s, can be reached by browsing to node dot cool. Simple code is less likely to have errors and more likely to be maintainable than complex code. There are no points for being clever. Some popular and useful n p m modules consist of three lines of code. Unless you are writing CLI commands, you probably want your app to be responsive while performing longer-running operations such as reads and writes, so you should choose asynchronous code over synchronous as much as possible. After all, most Node apps are web server applications, which are inherently multi-user. Put all your require statements at the top of the file because they are synchronous and will block the code’s execution. It’s better to block once on load than block the program randomly while it’s running.
Node Security Platform (node security dot I O) and Snyk (snick dot I O) can help you check that your code is secure and that your open source modules don’t have known vulnerabilities. Run your production servers like cattle, not like pets. If a server goes down, you should have a process manager in place to kill it and start a new instance. Common examples include the StrongLoop process manager, P M Two, and the Forever and forever-monitor N P M packages. The needs of a development server differ from the needs of a production server. Use nodemon (node'mon) instead of node to run your code, and your process will automatically restart when your code changes. It’s hard to catch errors in asynchronous code unless you check every error return value in every callback. The resulting messy code is sometimes called callback hell. The N P M okay package allows you to easily bubble errors up your callback chain. Thank you for joining us today for these 10 Node J S tips and tricks.