1
app.get('/',(req,res)=>{
 res.send("index.html ");});
app.listen(3000);
console.log("Server Started"); 

whenever i enter my local host IP address it displays "index.html" text instead of opening index.html file

1
  • Obvious when you look at the first example on express page: you are sending back the string index.html not the file. Commented Mar 19, 2019 at 10:02

1 Answer 1

5

You are trying to serve an HTML file, so you have to res.sendFile().

var express = require('express');
var app = express();
var path = require('path');

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

app.listen(3000);
Sign up to request clarification or add additional context in comments.

1 Comment

you dont need '/' when using path.join

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.