0

I wish to call my index.html page while using sendFile, but I ran into a problem. The problem is that it actually shows me the index.html although without any css and js\jquery effects.

server.js:

var express = require("express");
var app = express();

var server = app.listen(8000, function () {

var host = server.address().address;
var port = server.address().port;

console.log('Example app listening at http://%s:%s', host, port)

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

});
Matt Ellen
  • 11,268
  • 4
  • 68
  • 90
omri_saadon
  • 10,193
  • 7
  • 33
  • 58

1 Answers1

1

You need add this line to your code

app.use(express.static(__dirname + '/public')); // or another directory, it depends on where your static files are located

this is middleware to serve files from given directory, there is very good article about this middleware

Oleksandr T.
  • 76,493
  • 17
  • 173
  • 144