0

我是节点和表达的新手,我现在真的被困住了。我想从公用文件夹加载一个自定义 script.js,但它似乎没有加载。网络选项卡中没有任何内容,控制台中没有错误。当我访问 url:localhost:3000/javascripts/script.js 时,我看到了代码。我尝试了关于 SO 的所有答案,但似乎没有任何效果。使用快速生成器。我在这里做错了什么。

见代码: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;
4

1 回答 1

0
<script scr="/javascripts/script.js"></script>

应该

<script src="/javascripts/script.js"></script>
于 2016-11-21T21:03:30.133 回答