简体   繁体   English

NodeJS:使用其他文件夹的正确方法是什么?

[英]NodeJS: What is the correct way to use different folder?

I'm trying to develop a simple web app and I can't find a way to use different JS files stored in a different folder from the root one, I'll try to explain better.. this is my file structure: 我正在尝试开发一个简单的Web应用程序,但是我找不到一种方法来使用与根目录不同的文件夹中存储的不同JS文件,我将尝试更好地进行解释。这是我的文件结构:

myapp
├── clientSide
│   ├── getDown.js
│   ├── index.html
│   └── uptime.js
├── index.html.save
└── serverSide
    └── myapi.js

The server is running myapi.js and this is chunk of the code: 服务器正在运行myapi.js,这是代码的一部分:

app.use("/clientSide", express.static(__dirname + '/clientSide'));

console.log(__dirname);

exec("sudo /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'", function(error, stdout, stderr){
        ip = stdout;
                        exports.ipAdd = ip;
                        console.log(ip);
});

now..the problem is that from index.htm I can't import and use the JS files inside the clientSide directory using a simple 现在..问题是从index.htm我不能使用简单的方法导入并使用clientSide目录内的JS文件

<script src="clientSide/getDown.js"></script>

and

<script src="clientSide/uptime.js"></script>

can anyone please edit my piece of code in order to understand? 任何人都可以编辑我的代码以理解吗? Thanks! 谢谢!

在您的情况下,您无需将“ / clientSide”路径传递给app.use

app.use(express.static(__dirname +  '/clientSide')));

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

相关问题 NodeJS使用Promise的正确方法 - NodeJS correct way to use Promise 在jquery中使用“ this”的正确方法是什么? - What is the correct way to use “this” in jquery? 在 mysql2 nodejs 中将连接作为参数传递给不同的 function 的正确方法 - The correct way to passing connection as parameter to different function in mysql2 nodejs 处理NodeJS中潜在繁忙文件的正确方法是什么? - What's the correct way to handle removing a potentially busy file in NodeJS? 从异步回调NodeJS调用“父函数”的正确方法是什么 - What is the correct way to call “parent function” from asynchronous callback, NodeJS 在nodejs中为oracledb提交后释放连接的正确方法是什么 - what is the correct way to release connection after commit in nodejs for oracledb 使用nodejs和MySQL从数据库检索数据的正确方法是什么? - What is the correct way to retrieve data from database using nodejs and MySQL? 在Cordova中使用localForage的正确方法是什么? - What is the correct way to use localForage with Cordova? 使用 javascript .onclick 函数的正确方法是什么? - What is the correct way to use the javascript .onclick function? 在这种情况下使用对象销毁的正确方法是什么? - What is the correct way to use object destructing in this situation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM