问题
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