d
WE ARE EXPERTS IN TECHNOLOGY

Let’s Work Together

n

StatusNeo

Best Practices while working with node.js


Introduction

Node.js is one of the most popular javascript runtimes out there. It allows javascript code to run on the server-side fast because of its event loop-driven architecture. It is the engine responsible for fueling some of the most popular web applications today. In the following article, we cover some of the best practices and share resources on where to learn more about them.

Some common tips/tricks

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Use NPMS.io to find packages:
    • We can always search for packages on npmjs but if you are not happy with their search experience (like me) you can use options like npms.io for searching.
  6. Node.cool: List of awesome packages and modules curated in one place to help devs.
  7. Use Security Tools

Conclusion

In this short article, we discussed some informative links which can be very handy for developers working with Node.js

External Links:

  1. Openbase: https://openbase.com/
  2. Npms: https://npms.io/
  3. node cool: https://github.com/sindresorhus/awesome-nodejs
  4. Nodejs Security cheatsheet: https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html
  5. snyk: https://snyk.io/

Add Comment