Thursday 15 January 2015

Node.js accessing files from inside modules -



Node.js accessing files from inside modules -

i trying access file within module. have given file location within module below.my module folder called helper.

__dirname + "/../public/lib/objects"

500 error: enoent, no such file or directory '/home/sushmitsarmah/projects/app/helpers/public/lib/objects'

it gives me error location beingness helper/public/lib/objects. tried next:

__dirname + "/../../public/lib/objects". gives me error.

how should access public folder? in directory construction helper , public in same level.

folder structure:

app --helpers --getdata.js --public --lib --objects --views --app.js

in app.js call: var getdata = require('./helpers/getdata').getdata;

from within getdata.js want access objects folder.

thanks

note __dirname points directory executing script resides in. in our case directory script located. current working directory point folder of app.js __dirname alter according file in execution.

so path should be

__dirname + "/public/lib/objects" //from app.js

note:

in folder construction updated above, when in getdata.js, value of __dirname "/rootpath/app/helpers". objects folder there, have do

__dirname + "/../public/lib/objects" //from getdata.js

node.js

No comments:

Post a Comment