Home > database >  Express app.get() code in server not updating but other server code will update
Express app.get() code in server not updating but other server code will update

Time:10-11

I have a node js and express server I run on localhost. Recently, while changing the server code from

app.get('/', (req, res) => {
    res.sendFile(__dirname   '/public/index.html');
});

to

app.get('/', (req, res) => {
    res.send('home');
});

The server still serves the "index.html" file and does not send the message "home". I also tried deleting all my "app.get()" and "app.post()" functions and it still runs as it was before the changes. I have double checked that I saved the file and restarted the server but even then, still does the same thing. The odd thing is that when changing anything else in the server code aside from my express code it runs as expected.

I tried searching my problem but no one is experiencing the same issues. Any help is appreciated, thanks.

CodePudding user response:

All of your code is not listed, so this is an educated guess, but I would check to see if you are using express.static or another package to serve the directory your index.html file is in via app.use() before your routes. By default express.static will serve index.html if presented a root path ('/').

  • Related