Skip to content

Instantly share code, notes, and snippets.

@morficus
Last active May 24, 2018 20:23
Show Gist options
  • Select an option

  • Save morficus/2038b4b060d69923c106429f47e6a26d to your computer and use it in GitHub Desktop.

Select an option

Save morficus/2038b4b060d69923c106429f47e6a26d to your computer and use it in GitHub Desktop.
Serving an HTML file
/*
Here are three options to display an HTML file.
Put any of them on line 13 of index.js
*/
// option 1: if you just show some plain text to confirm things are running
app.get('/', (req, res) => {
res.set('Content-Type', 'text/plain').send('Type text you want to display here');
})
// option 2: if you actually want serve up a single html file (no external resources like images or CSS files)
app.get('/', (req, res) => {
res.sendFile('./index.html')
})
// option 3: if you want to server up an entire static site (all your static things would go in a directory of your choice ("public" in this example)
// then in that "public" directory you can place your index.html and any CSS or image files you want
app.use(express.static(__dirname + '/public'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment