javascript - Change current folder in Node.js -
i have file fetching other files:
start.js
require("./users");
but users.js file not in current folder in model/.
i want able run:
node start.js model
and assume ./ same model/ in start.js.
how do that?
all need make node.js recognize folder model
module.
in order that, need place file called index.js
inside model
folder.
// model/index.js exports.users = require('./users'); // model/users.js exports.posts = require('./posts'); // model/posts.js // etc.
now can import model
module , access it's exports:
var models = require('./model'); models.users.create(); // function exported in model/users.js models.posts.list(); // exported in model/posts.js
Comments
Post a Comment