[英]Getting a 404 error when trying to link my array.js file
I am using node.js to run locally (To start the server I am using: "node index.js" in my terminal) and I keep getting this error when I try to link my array.js file. 我正在使用node.js在本地运行(要启动服务器,我正在使用:终端中的“ node index.js”),当我尝试链接array.js文件时,我一直收到此错误。
GET http://localhost:3000/array.js 404 (Not Found)
My file paths are as such if that matters... 我的文件路径就这么重要...
/Campus/views(Index.pug file)
/Campus(Index.js file)
/Campus/public/js(array.js file)
My HTML(pug syntax) Header: 我的HTML(pug语法)标头:
doctype html
head
script(src='array.js', type='text/javascript')
link(rel='stylesheet', type='text/css', href='http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css')
link(rel='stylesheet', type='text/css', href='http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css')
I feel that I did indeed reference my .js file correctly here, but this is my first time using node.js and maybe there is something I am over looking. 我觉得我确实确实在这里正确引用了我的.js文件,但这是我第一次使用node.js,也许我正在寻找一些东西。
My Index.js code: 我的Index.js代码:
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 3000));
app.use(express.static(__dirname + '/public'));
// views is directory for all template files
app.set('views', 'views');
app.set('view engine', 'pug');
app.get('/', function(request, response) {
response.render('index', {
title: 'Homepage'
});
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
You put it in public/js/array.js, but you're referencing it in public/array.js. 您将其放在public / js / array.js中,但在public / array.js中引用了它。 Your path should be js/array.js 您的路径应为js / array.js
Documentation: https://expressjs.com/en/starter/static-files.html 文档: https : //expressjs.com/en/starter/static-files.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.