Created
September 14, 2021 17:44
-
-
Save AhmedAbouelkher/41edccb0fdb4a58008ecb377530a9b2f to your computer and use it in GitHub Desktop.
js app templete
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 express = require('express'); | |
const p = require('path'); | |
const expressLayouts = require('express-ejs-layouts'); | |
const app = express() | |
app.set('view engine', 'ejs') | |
app.set('views', p.join(__dirname, 'views')) | |
app.set('layout', 'layouts/layout') | |
app.use(expressLayouts) | |
app.use(express.static('public')) | |
app.use(express.json()) | |
app.use(express.urlencoded({ extended: true })) | |
app.get('/', (req, res, next) => { | |
res.send({ msg: "Hello world" }) | |
}) | |
app.use((err, req, res, next) => { | |
res.status(500).json({ error: err.message, code: err.statusCode }); | |
}); | |
app.listen(process.env.PORT, () => console.log(`Started on port ${process.env.PORT}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment