Create Your Own Node Module
cd node_modules mkdir myCoolModule cd myCoolModule touch index.js npm init (answer yes to all) exports.? all functions and variables you want to be used in other places. /*for react*/ import {?1, ?2} from 'myCoolModule' /*for expressJS*/ const myCoolModule = require('myCoolModule'); myCoolModule.?1 myCoolModule.?2
Create Your Own Node Module
mycoolmodule/index.js export.a = "AAAAAA; exports.hw = function() { console.log("Hello World!"); } /*you can exports as many variables and functions as you want*/ routes/index.js var express = require('express'); var mymodule = require('mycoolmodule') var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { mymodule.hw(); /* console.log(mymodule.a) will yield AAAAAA*/ }); module.exports = router;