Skip to content

Instantly share code, notes, and snippets.

@elpuas
Last active April 6, 2021 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elpuas/ec6b299646a099fca58846ab10b8efe0 to your computer and use it in GitHub Desktop.
Save elpuas/ec6b299646a099fca58846ab10b8efe0 to your computer and use it in GitHub Desktop.
const express = require('express')
const app = express()
// path is a built in module in Node
// It Helps get the specific path to the files
const path = require('path')
// Add the Public Folder for Assets
app.use(express.static('public'))
app.listen( 3000, () => {
console.log('App listening on port 3000')
})
// App Routes
app.get('/', ( req, res ) => {
res.sendFile( path.resolve( __dirname, 'index.html') )
})
app.get('/about', ( req, res ) => {
res.sendFile( path.resolve( __dirname, 'about.html') )
})
app.get('/contact', ( req, res ) => {
res.sendFile( path.resolve( __dirname, 'contact.html') )
})
app.get('*', (req, res) => {
res.sendFile( path.resolve(__dirname, '404.html'))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment