Home > Hot in web development > 10 Tips to Become a Better Node Developer in 2017

10 Tips to Become a Better Node Developer in 2017

10 Tips to Become a Better Node Developer in 2017 is by guest author Azat Mardan. SitePoint guest posts aim to bring you engaging content from prominent writers and speakers of the Web community.

I started working with Node full-time in 2012 when I joined Storify. Since then, I have never looked back or felt that I missed Python, Ruby, Java or PHP — languages with which I had worked during my previous decade of web development.

Storify was an interesting job for me, because unlike many other companies, Storify ran (and maybe still does) everything on JavaScript. You see, most companies, especially large ones such as PayPal, Walmart, or Capital One, only use Node for certain parts of their stack. Usually they use it as an API gateway or an orchestration layer. That’s great. But for a software engineer, nothing compares with full immersion into a Node environment.

In this post I’ll outline ten tips to help you become a better Node developer in 2017. These tips come from me, who saw and learned them in the trenches, as well as people who have written the most popular Node and npm modules. Here’s what we’ll be covering:

  1. Avoid complexity — Organize your code into the smallest chunks possible until they look too small and then make them even smaller.
  2. Use asynchronous code — Avoid synchronous code like the plague.
  3. Avoid blocking require — Put ALL your require statements at the top of the file because they are synchronous and will block the execution.
  4. Know that require is cached — This could be a feature or a bug in your code.
  5. Always check for errors — Errors are not footballs. Never throw errors and never skip the error check.
  6. Use try…catch only in sync code — try…catch is useless for async code, plus V8 can’t optimize code in try…catch as well as plain code.
  7. Return callbacks or use if … else — Just to be sure, return a callback to prevent execution from continuing.
  8. Listen to the error events — Almost all Node classes/objects extend the event emitter (observer pattern) and emit the error event. Be sure to listen to that.
  9. Know your npm — Install modules with -S or -D instead of –save or –save-dev
  10. Use exact versions in package.json: npm stupidly adds a caret by default when you use -S, so get rid of them manually to lock the versions. Never trust semver in your apps, but do so in open-source modules.
  11. Bonus — Use different dependencies. Put things your project needs only in development in devDependencies and then use npm i –production. The more un-required dependencies you have, the greater the risk of vulnerability.

So let’s bisect and take a look at each one of them individually. Shall we?

Read Full Article

This article and image was adapted from sitepoint.com

By Azat Mardan

admin
The WebRecital is a dedicated User Interface/User Experience professionals who come together to provide design and research workshops, portfolio reviews, and educational outreach to the greater Seattle area.
http://webrecital.com/

Leave a Reply

Your email address will not be published. Required fields are marked *