The node js server is not loading my website files

天大地大妈咪最大 提交于 2019-11-30 09:41:45

问题


When I run node index.js the browser loads only the html, disregarding javascript, images, and css , and if I try to access a link it shows a blank plage: node.js Cannot GET /login.html, how do I fix that?

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http); 
var myList = new Array();
var i = 0;

app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html', {});
});

回答1:


You need show the error with your question and "/login.html" file?

Or quick-fix, you can change your code as below:

res.sendFile(__dirname + '/index.html', {});

to

res.render('index.html', { /*data*/ });



回答2:


Here you have some code to tell your server what to when when the browser requests /.

app.get('/'

You haven't written anything to tell it what to do when the browser requests /login.html. Write something for that case.



来源:https://stackoverflow.com/questions/35776556/the-node-js-server-is-not-loading-my-website-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!