Best Practices while working with node.js
Some common tips/tricks
- Keep Your code simple:
- Try to keep your code simple and straightforward. No need to introduce irrelevant dependencies. Knowing what to use where is very important.
- Write Async Code:
- Node.js is asynchronous. It’s not recommended to execute it in a synchronous way unless absolutely necessary. So, try to run your code in an asynchronous way as much as possible.
- Put all require statements on top:
- Requiring packages works in a synchronous way and it’s better to include the packages at the top and let all of them be included at once. Instead of stopping the code flow in between by including it in the middle of the code.
- Use NPM packages
- Try to avoid reinventing the wheel by working on something which is already been done. Instead, focus more on understanding why to use a specific package. Knowing which package to use where is a skill in itself.
- If you are not sure as to decide Compare millions of open-source packages with reviews, insights & categories using openbase.
- Use NPMS.io to find packages:
- Node.cool: List of awesome packages and modules curated in one place to help devs.
- Use Security Tools
In this short article, we discussed some informative links which can be very handy for developers working with Node.js
- Openbase: https://openbase.com/
- Npms: https://npms.io/
- node cool: https://github.com/sindresorhus/awesome-nodejs
- Nodejs Security cheatsheet: https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html
- snyk: https://snyk.io/