node.js - Express : Cannot Find Module? -
i using express routing, , want call function inside static javascript file signup.js, error saying 
error: cannot find module './js/list.js'    my directory structure follows:
app.js -routes/signup.js -public/js/list.js   in app.js file, have line:
app.use(express.static(path.join(__dirname, 'public')));   in signup.js, have:
var listmodel = require('./js/list.js');   my list.js file contains:
module.exports.list = function (username, category) {    return ({     "owner" : usernamename,     "category" : category,     "completed" : [],     "planned" : [],     "current" : [],     "dropped" : [],     "onhold"  : []   }); }   is there else missing in order import list function signup file? thanks!
since have different signup , list have different parent directories, nodejs require function not consider them siblings. need write
var listmodel = require('../public/js/list.js');   inside of routes/signup.js
if had file public/test.js indeed use
var listmodel = require('./js/list.js');   to require dependency within it.
Comments
Post a Comment