[英]basic app with es6 modules not working chrome - ERR_ABORTED 404 (Not Found)
我正在创建一个带有 es6 模块的基本应用程序,并与节点服务器做出反应。 index.html 将 index.js 文件作为模块提供,但该模块未加载并且控制台显示错误:GET http://localhost:3000/index.js net::ERR_ABORTED 404 (Not Found)
https://codesandbox.io/embed/veriz-210fb
https://github.com/stanleyjohnson/veriz
复制:clone repo, npm i, npm start, 转到http://localhost:3000
您应该通过server.js
下行添加到server.js
文件来启用静态文件服务:
app.use('/', express.static(__dirname + '/'));
所以你的文件应该是这样的:
const express = require('express')
const app = express()
const port = 3000
app.use('/', express.static(__dirname + '/'));
app.get('/', function(req, res) {
res.sendFile('index.html',{ root: __dirname });
});
app.listen(port);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.