简体   繁体   English

如何将某些Node.js文件放置在Node.js应用程序根文件夹之外?

[英]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/ . 我想将Node单元测试放在应用程序根目录文件夹/test/server/ The problem is that when I put my Node files there, Node doesn't see my node_modules . 问题是,当我将Node文件放在那里时,Node看不到node_modules My Node app is at /server/ . 我的Node应用程序位于/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" 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 编辑:现在,我再次查看了您的require语句,我看到您正在为要尝试的模块指定扩展名,删除该扩展名,您应该能够找到该模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 node.js express 如何访问我的公共文件夹中的文件 - How to access files in my public folder in node.js express 如何从Node.js / Express.js中的CDN提供我的根页面? - How can I serve my root page from a CDN in Node.js / Express.js? 我可以在Windows Phone 8应用程序中使用Node.js吗? - Can I use Node.js into my windows phone 8 application? 如何在REACT中为连接到node.js的Axios路由创建一个单独的文件夹 - How can i create a separate folder in REACT for my Axios routes, that are connected to my node.js 如何在 linux 中找到我的 node.js 文件,/usr/bin/node 不工作 - how can I find my node.js files in linux, /usr/bin/node is not working 如何在启动时运行某个文件夹中的所有 node.js 文件? - How to run all node.js files in some folder on startup? 如何故意使我的node.js服务器崩溃? - How can I purposefully crash my node.js server? 如何使用 node.js 修改我的 HTML 文件? - How can I modify my HTML file with node.js? 如何在Node.js中的循环中为背景设置动画 - How can I animate my background in a loop in node.js Node.js:组织我的应用程序:在单独的文件中使用路由和模型,如何从路由中获取模型? - Node.js : organising my application : using routes and models in separate files, how can I get models from routes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM