Skip to main content
fix codesample
Source Link
Bruno Schäpper
  • 1.9k
  • 2
  • 14
  • 24

There are certainly lots and lots of options, which are all commonly used. But that's terribly annoying. I like to put it at the end, because that works under all circumstances. Whenever I find myself doing something fancy with module.exports, there is probably a better way to do it.

Most importantly, as always, be consistent. And be consistent in your team.

EDIT: On the same notion, I like to have all require statements at the beginning. My Node.js files always look like this:

"use strict"; varconst fs = require("fs"); varconst MyClass = require("./MyClass"); class MyOtherClass classextends MyClass {} module.exports = MyOtherClass; 

Nothing fancy, just the way you would expect it. One class per file, one file per class. Files named after the class they contain, with consisten upper/lowercasing. Have a look at this node module, for some examples: yaioc (disclaimer: I'm the author, and this is shameless advertising)

There are certainly lots and lots of options, which are all commonly used. But that's terribly annoying. I like to put it at the end, because that works under all circumstances. Whenever I find myself doing something fancy with module.exports, there is probably a better way to do it.

Most importantly, as always, be consistent. And be consistent in your team.

EDIT: On the same notion, I like to have all require statements at the beginning. My Node.js files always look like this:

"use strict"; var fs = require("fs"); var MyClass = require("./MyClass"); class MyOtherClass class {} module.exports = MyOtherClass; 

Nothing fancy, just the way you would expect it. One class per file, one file per class. Files named after the class they contain, with consisten upper/lowercasing. Have a look at this node module, for some examples: yaioc (disclaimer: I'm the author, and this is shameless advertising)

There are certainly lots and lots of options, which are all commonly used. But that's terribly annoying. I like to put it at the end, because that works under all circumstances. Whenever I find myself doing something fancy with module.exports, there is probably a better way to do it.

Most importantly, as always, be consistent. And be consistent in your team.

EDIT: On the same notion, I like to have all require statements at the beginning. My Node.js files always look like this:

"use strict"; const fs = require("fs"); const MyClass = require("./MyClass"); class MyOtherClass extends MyClass {} module.exports = MyOtherClass; 

Nothing fancy, just the way you would expect it. One class per file, one file per class. Files named after the class they contain, with consisten upper/lowercasing. Have a look at this node module, for some examples: yaioc (disclaimer: I'm the author, and this is shameless advertising)

added 642 characters in body
Source Link
Bruno Schäpper
  • 1.9k
  • 2
  • 14
  • 24

There are certainly lots and lots of options, which are all commonly used. But that's terribly annoying. I like to put it at the end, because that works under all circumstances. Whenever I find myself doing something fancy with module.exports, there is probably a better way to do it.

Most importantly, as always, be consistent. And be consistent in your team.

EDIT: On the same notion, I like to have all require statements at the beginning. My Node.js files always look like this:

"use strict"; var fs = require("fs"); var MyClass = require("./MyClass"); class MyOtherClass class {} module.exports = MyOtherClass; 

Nothing fancy, just the way you would expect it. One class per file, one file per class. Files named after the class they contain, with consisten upper/lowercasing. Have a look at this node module, for some examples: yaioc (disclaimer: I'm the author, and this is shameless advertising)

There are certainly lots and lots of options, which are all commonly used. But that's terribly annoying. I like to put it at the end, because that works under all circumstances. Whenever I find myself doing something fancy with module.exports, there is probably a better way to do it.

Most importantly, as always, be consistent. And be consistent in your team.

There are certainly lots and lots of options, which are all commonly used. But that's terribly annoying. I like to put it at the end, because that works under all circumstances. Whenever I find myself doing something fancy with module.exports, there is probably a better way to do it.

Most importantly, as always, be consistent. And be consistent in your team.

EDIT: On the same notion, I like to have all require statements at the beginning. My Node.js files always look like this:

"use strict"; var fs = require("fs"); var MyClass = require("./MyClass"); class MyOtherClass class {} module.exports = MyOtherClass; 

Nothing fancy, just the way you would expect it. One class per file, one file per class. Files named after the class they contain, with consisten upper/lowercasing. Have a look at this node module, for some examples: yaioc (disclaimer: I'm the author, and this is shameless advertising)

Source Link
Bruno Schäpper
  • 1.9k
  • 2
  • 14
  • 24

There are certainly lots and lots of options, which are all commonly used. But that's terribly annoying. I like to put it at the end, because that works under all circumstances. Whenever I find myself doing something fancy with module.exports, there is probably a better way to do it.

Most importantly, as always, be consistent. And be consistent in your team.