Files

19 lines
711 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Serve an HTML File
---
# Serve an HTML File
2018-10-12 15:37:13 -04:00
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
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:
```javascript
app.get("/", function(req, res) {
res.sendFile(__dirname + "/public/index.html");
});
2018-10-12 15:37:13 -04:00
```
**Note:** __dirname returns the root directory is a best practice for node developers.