简体   繁体   English

尝试链接我的array.js文件时出现404错误

[英]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.

相关问题 尝试包含angular.min.js文件时出现404错误 - Getting 404 error when trying to include angular.min.js file NodeJS 应用程序:尝试链接时,scripts/main.js 出现错误 404 - NodeJS app: error 404 for scripts/main.js when trying to link 尝试对 Hubspot 表单 next.js 应用程序发出 api POST 请求时出现 404 错误 - Getting a 404 ERROR when trying to make api POST request for a Hubspot form next.js app 试图将 csv 数据获取到 javascript 数组并出现 404 错误 - Trying to get csv data to javascript array and getting 404 error 尝试在浏览器中的 html 文件中加载 functions.js 文件时出现 GET 404 错误(*使用节点 js 作为服务器) - GET 404 Error When Trying to Load a functions.js File Inside an html File in Browser (*using node js as server) 从带有内联的 html 文件加载 js 文件时出现 404 错误<script> - Getting a 404 error when loading js file from an html file with inline <script> 尝试登录到express和node.js内置的身份验证系统时出现404错误(找不到文件) - 404 ERROR(file not found) when trying to log to an authentication system built in express and node.js 使用Spring将JS文件添加到JSP文件时获取404 - Getting 404 when adding a JS file to a JSP file using spring 尝试让 Express 和 React 连接时出现 404 错误 - Getting a 404 error when trying to get Express and React to connect 使用 js 文件中的数组时出错 - Getting an error when using an array from a js file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM