Difference between revisions of "Import Export in Node"
From Logic Wiki
(Created page with "Category:Node.js == Export == <pre class="brush:js;"> var url = 'http://...'; function log(message){ console.log(message) } module.exports.log = log; module.exports.e...") |
|||
| Line 19: | Line 19: | ||
path is relative and there sis no need to write the js extension | path is relative and there sis no need to write the js extension | ||
| + | |||
| + | if it's a built in module we write it directly like '''require('path')''' | ||
Latest revision as of 19:38, 13 September 2018
Export
var url = 'http://...';
function log(message){
console.log(message)
}
module.exports.log = log;
module.exports.endPoint = url;
so the exported name can be different like endPoint
Import
const logger = require('./logger');
console.log(logger);
path is relative and there sis no need to write the js extension
if it's a built in module we write it directly like require('path')