Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Nodejs module working only in some folders

Nodejs module working only in some folders


It's weird I have a little request (in nodejs) ( request_working.js ) that require the request module The problem is that it works only in some folder because otherwise the module is not found! For example my folders are this way : /home/lol/Desktop/nodejs/ newProject/newProject/node_modules

So node request_working.js work in the bold folders (working in the nodejs and newProject folder but not in the other newProject folder or in node_modules folder) Because I have this error :

        throw e; // process.nextTick error, or 'error' event on first tick
TypeError: Object # has no method 'post'
    at Object. (/home/lol/Desktop/nodejs/newProject/newProject/request_working.js:3:9)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)
    at EventEmitter._tickCallback (node.js:192:40)

Like if I didn't have request module. (I am using a POST method from the request module) I am using Express.js ( the newProject folder = Express project ) so I want to put my request_working.js in


to use it as a module. But how wan I fix this error first ? Thanks !

Problem courtesy of: Louis


Thanks david, it's working !

How to fix this error ? : in console type : node then module It should gives you all the node_modules folders, for example: home/lol/newproject/node_modules then go in the folder newproject if it does not already existcreate a new folder node_modules, put you modules in this folder and delete every node_modules deeper in the directory example you should delete: home/lol/newproject/newproject/node_modules

THanks again !

Solution courtesy of: Louis


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Nodejs module working only in some folders


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription