Skip to content

Instantly share code, notes, and snippets.

@cyberplanner
Created October 22, 2017 17:07
Show Gist options
  • Save cyberplanner/dc509b7cdce543f41ef42d57bb925a27 to your computer and use it in GitHub Desktop.
Save cyberplanner/dc509b7cdce543f41ef42d57bb925a27 to your computer and use it in GitHub Desktop.
Node js notes

Notes:

Exporting:

Exporting functions:

// in module.js
exports.randomNum = fucntion() {
  return Math.random();
}

// exports a function (attaches it to the exports object on the global node object) and you can require the module and call the function like so:
var module = require("./module.js");
console.log(module.randomNum());

Exporting single function:

// in module.js
module.exports  = function() {
  return Math.random();
}
// and call the whole module as a function:
var module = require("./module.js");
console.log(module());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment