javascript - How to locate the right path for a .js file when using require -
i have expressjs project want use .js module inside another. use require .js module can't find module because path not correct. how can see or find correct path local module.
here project hierarchy/structure 
this have tried inside programcontroller.js - thing don't quite understand using "." in path string.
var program = require('.././program.js'); var finishprogram = require('.././finishprogram');
the . , .. notation in paths represent path relative file they're being required from.
meaning of . , .. wildcards
. - inside same directory file in (also referred current working directory)
.. - inside parent directory of current directory
when use multiples of these creates relative path pattern. programcontroller.js access program.js path should be
var program = require('../../models/program');
this path means, go 2 folders app directory , locate models folder, load file program.js.
following same rules, can access finishprogram.js
var finishprogram = require('../../models/finishprogram');
Comments
Post a Comment