* Expanded the solution for the 'Get Route Parameter Input from the Client' challenge * Expanded the guide for the 'Use body-parser to Parse POST Requests' challenge * Rewritten guide for the 'Serve JSON on a Specific Route' challenge and fixed source link * Expanded the guide for the 'Serve Static Assets' challenge * Expanded solution to the 'Get Query Parameter Input from the Client' challenge and fixed links to source file * Added solution to the 'Chain Middleware to Create a Time Server' challenge and fixed link to source file * Rewrite the 'Start a Working Express Server' challenge * Expanded the guide for 'Expand Your Project with External Packages from npm' * Added reference to semantic versioning in 'Add a Version to Your package.json' * fix/remove-links+fix-solutions * fix/remove-more-links
821 B
821 B
title
title |
---|
Serve an HTML File |
Serve an HTML File
You probably need to comment out the last challenge. If you have a website and want to serve an index.html file you probably want to put this in a public folder. This is to ensure the public doesn't see something you dont want them to, and it sometimes is called "public" or "views," but you can technically call it whatever you want.
To serve an index.html in a folder called "public" at the root domain you would do so like this:
app.get("/", function(req, res) {
res.sendFile( __dirname + "/public/index.html");
});
Note: __dirname returns the root directory is a best practice for node developers.