|
||||||||
NodeJS What is NodeJS and what is MEAN
WHY NodeJS?
|
|
2 Ways to create a module
module.exports = { sayHelloInEnglish: function() { return "HELLO"; }, sayHelloInSpanish: function() { return "Hola"; } };
// greetings.js var exports = module.exports = {}; exports.sayHelloInEnglish = function() { return "HELLO"; }; exports.sayHelloInSpanish = function() { return "Hola"; };
how to import (require) a module into a NodeJS file
The keyword
// main.js var greetings = require("./greetings.js"); // "Hello" greetings.sayHelloInEnglish(); // "Hola" greetings.sayHelloInSpanish();
require
returns an object, which references the value ofmodule.exports
for a given file
how to install a module in your application director
$npm install <module name>