Skip to content

Instantly share code, notes, and snippets.

@code08-ind
Created June 21, 2021 18:15
Show Gist options
  • Save code08-ind/1c3a93ae4ab2f3f05cb7685d62b1b152 to your computer and use it in GitHub Desktop.
Save code08-ind/1c3a93ae4ab2f3f05cb7685d62b1b152 to your computer and use it in GitHub Desktop.
const path = require('path');
const express = require('express');
const app = express();
const port = 8000;
const localHost = '127.0.0.1';
const staticPath = path.join(__dirname, '../public');
const viewsPath = path.join(__dirname, '../views');
app.set('view engine', 'ejs');
app.use(express.static(staticPath));
app.set('views', viewsPath);
app.get('/', (req, res) => {
res.render('Home', { title: "Home Page" });
});
app.get('/about', (req, res) => {
res.render('About', { title: "About Page" });
});
app.get('/*', (req, res) => {
res.render('Error', { title: "Error Page" });
});
app.listen(port, localHost, () => {
console.log(`Server Listening At Port ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment