[英]Not loading custom scripts from public folder Express (generator)
I am a newbie to node and express and I am really stuck right now. 我是节点表达的新手,现在真的很困。 I want to load a custom script.js form the public folder but it doesnt seem to load.
我想从公共文件夹加载自定义script.js,但似乎没有加载。 Nothing in the network tab, no errors in the console.
网络选项卡中没有任何内容,控制台中没有错误。 When I to go the url: localhost:3000/javascripts/script.js, I am seeing the code.
当我转到URL:localhost:3000 / javascripts / script.js时,我看到了代码。 I tried every answer given on SO, but nothing seems to work.
我尝试了所有关于SO的答案,但似乎没有任何效果。 Using the express generator.
使用快速生成器。 What am I doing wrong here.
我在这里做错了。
See code: app.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 file 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 file: 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;
<script scr="/javascripts/script.js"></script>
应该
<script src="/javascripts/script.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.