I'm using express to serve files and everything is working but I can't get my console.log statement to show in app.get() route statment. I'm currently using app.use(express.static("public")); to serve from the public folder.
Here is the full code:
//Server static files from the public folder.
app.use(express.static("public"));
app.listen(PORT, function(){
console.log("Sever is running and listening on port: " +PORT);
});
//Establish routes
app.get('/', function (req, res) {
//res.sendFile('/student-profile');
res.send("This is the response.");
});
1) How can I get this work?
2) Also, is the index.html the first file that is looked for when serving static files from the public folder?
const express = require('express'); const app = express();?app.get('/')when usingexpress.static('public');However, you will need a post route method for any POST requests.