Skip to content

Instantly share code, notes, and snippets.

@capaj
Created January 31, 2016 11:07
Show Gist options
  • Save capaj/dbd41bee14acf04a9c71 to your computer and use it in GitHub Desktop.
Save capaj/dbd41bee14acf04a9c71 to your computer and use it in GitHub Desktop.

This rule should only be enforced for node.js > 0.12 There is no point in declaring a module as var. Module should always be a const if assigned on the same line as the require statement is. If you want to require module "A" or module "B" into a single variable, it should be done like this:

var aOrB
if (cond) {
  aOrB = require('A')  
} else {
  aOrB = require('B')
}

if you would have do it like this:

var aOrB  = require('A')  
if (cond) {
  aOrB = require('B')
}

That would be bad, because that way you are forcing node to load module "A" even if cond is true.

Thanks for you consideration and please let me know if I forgot some

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment