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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -