[英]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.