简体   繁体   中英

How can I place some of my Node.js files outside of my Node.js application root folder?

I want to put my Node unit tests in an application root level folder, /test/server/ . The problem is that when I put my Node files there, Node doesn't see my node_modules . My Node app is at /server/ .

My app folder is structured like this:

|- server/ (where my Node.js stuff is)
| |- package.json
| |- server.js
| |- etc
|- client/ (where my AngularJS and front-side stuff are)
| |- index.jade
| |- CSS/
| |- etc
|- test/ (where my unit tests are)
| |- server/
| |- client/

How can I solve this problem?

you need to set node path in your environment

NODE_PATH="/path/to/node_modules"

then you should be able to reference them

EDIT: Now that I had a second look at your require statement I see that you are specifying an extension for the module you are trying to require, remove that and you should be able to find the module

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM