这是我的HTML:
<!DOCTYPE html>
<html>
<head><% include ./header %>
<link type="text/javascript" src="loginScript" ></head>
<body class='home-page' ng-app="loginApp" ng-controller="LoginCtrl"> </body></html>
header.ejs 我的申请
<script type="text/javascript" src="/node_modules/jquery/dist/jquery.min.js">
</script>
server.js
var express = require('express');
var app = express();
var mysql = require('mysql');
var path = require('path');
var http = require('http');
var fs = require('fs');
var bodyParser = require('body-parser');
app.set('view engine','ejs');
app.get('/',(req,res) =>{
res.render('./login_page');
});
app.use(express.static(path.join(__dirname, 'public')));
var server = http.createServer();
app.listen(8081);
运行节点server.js
时,显示以下错误:
本地主机/:12 GET
http://localhost:8081/node_modules/jquery/dist/jquery.min.js 404(未找到)
localhost/:1 Refused to execute script from
'http://localhost:8081/node_modules/jquery/dist/jquery.min.js' because
its MIME type ('text/html') is not executable, and strict MIME type
checking is enabled.
我有node_modules/jquery/dist/jquery.min.js
,但我不知道为什么会收到此错误。
答案 0 :(得分:0)
您实际上是在尝试提供静态资源,因此您必须启用一个路径来定位静态文件,例如脚本,css,图像等
如果您将Expressjs用于后端,请检查此链接http://expressjs.com/es/starter/static-files.html
答案 1 :(得分:0)
解决方案:
我解决了这个问题,我在server.js中声明了静态路径路由,因此这是我的静态路径, 所以我必须从(../node_modules/jquery/dist/jquery.min.js)之类的路径中调用文件
<script type="text/javascript" src="../node_modules/jquery/dist/jquery.min.js">
</script>