Created
October 17, 2024 22:30
-
-
Save joshcanhelp/53408479a5da1af03e80308c05da0b2b to your computer and use it in GitHub Desktop.
Basic Express template
This file contains 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
import express from "express"; | |
const { APP_PORT } = process.env; | |
const appPort = parseInt(APP_PORT, 10) || 3000; | |
const app = express(); | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: true })); | |
app.get("/", (request, response) => { | |
response.send("OK"); | |
}); | |
app.use((error, request, response, next) => { | |
response.send( | |
getHeader(request, "ERROR") + | |
`<p><strong>Error message:</strong></p>` + | |
`<blockquote>${error.message}</blockquote>` + | |
`<p><strong>URL params:</strong></p>` + | |
`<pre>${JSON.stringify(request.query, null, 2)}</pre>` + | |
getFooter() | |
); | |
}); | |
app.listen(appPort, () => { | |
console.log(`App is running at http://localhost:${appPort}`); | |
}); |
This file contains 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
{ | |
"name": "basic-express-template", | |
"version": "0.1.0", | |
"main": "app.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "dotenvx run -- nodemon app.js" | |
}, | |
"type": "module", | |
"license": "MIT", | |
"devDependencies": { | |
"@dotenvx/dotenvx": "^1.20.0", | |
"nodemon": "^3.1.7" | |
}, | |
"dependencies": { | |
"express": "^4.21.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment