Created
February 12, 2022 14:26
-
-
Save NikhilNanjappa/a22b815741da8bc079caa2360e16e012 to your computer and use it in GitHub Desktop.
GDS Demo complete app.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const nunjucks = require('nunjucks') | |
const express = require('express') | |
const app = express() | |
const port = 3004 | |
nunjucks.configure([ | |
path.join(__dirname, 'node_modules/govuk-frontend/'), | |
path.join(__dirname, 'app/views/') | |
], { | |
autoescape: true, | |
express: app, | |
noCache: true, | |
watch: true | |
}) | |
app.set('view engine', 'html') | |
app.use(express.static(path.join(__dirname, 'public'))) | |
app.use('/assets', express.static(path.join(__dirname, '/node_modules/govuk-frontend/govuk/assets'))) | |
app.use('/govuk-frontend', express.static(path.join(__dirname, '/node_modules/govuk-frontend/govuk'))) | |
app.get('/', (req, res) => { | |
return res.render('layout') | |
}) | |
// Run the application | |
app.listen(port, () => { | |
console.log(`App running on => http://localhost:${port}`) | |
}).on(('error'), (err) => { | |
if (err.errno === 'EADDRINUSE') { | |
console.log(`----- Port ${port} is busy. Please use another port.`) | |
} else { | |
console.log(err) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment