[英]expressjs unable to load script
I'm using expressJS framework. 我正在使用expressJS框架。 I get the JS load problem on browser console. 我在浏览器控制台上遇到了JS加载问题。 Can you tell me what is the problem here? 你能告诉我这里有什么问题吗?
var express = require('express');
var fs = require('fs');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser());
express.static(__dirname);
app.get('/', function(req, res){
fs.readFile('index.html', 'utf8', function(err, text){
res.send(text);
});
});
And this is how I include JS in index.html is 这就是我在index.html中包含JS的方式
<script src="testscript.js"></script>
Folder structure is 文件夹结构是
- src
- index.html
- server.js
- testscript.js
express.static()
返回一个中间件函数,你必须告诉你的应用程序使用它。
app.use(express.static(__dirname));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.