我是节点和表达的新手,我现在真的被困住了。我想从公共文件夹加载自定义script.js但它似乎没有加载。网络选项卡中没有任何内容,控制台中没有错误。当我去url:localhost:3000 / javascripts / script.js时,我看到的是代码。我尝试了所有给出的答案,但似乎没有任何效果。使用快速发电机。我在这做错了什么。
参见代码: app.js
var express = require('express');
var path = require('path');
var index = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/users', users);
index.ejs文件
<html>
<head>
<!-- include head -->
<% include partials/head.ejs %>
</head>
<body>
<% include partials/header.ejs %>
<% include partials/footer.ejs %>
<script scr="/javascripts/script.js"></script>
</body>
</html>
index.js文件:
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;
答案 0 :(得分:0)
<script scr="/javascripts/script.js"></script>
应该是
<script src="/javascripts/script.js"></script>