Pratik Vanjare
Pratik Vanjare

Reputation: 21

Serve an HTML file in node.js

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

Upvotes: 1

Views: 108

Answers (1)

yacine benzmane
yacine benzmane

Reputation: 4188

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);

Upvotes: 5

Related Questions