Skip to content

Instantly share code, notes, and snippets.

@theinfosecguy
Created February 22, 2023 12:39
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 theinfosecguy/0d6b27091158402983481915edeb1cc6 to your computer and use it in GitHub Desktop.
Save theinfosecguy/0d6b27091158402983481915edeb1cc6 to your computer and use it in GitHub Desktop.
Entry Point for Sample NodeJS App for Deployment
const express = require('express');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const compression = require('compression');
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static('public'));
let todoList = ["Buy Eggs"];
app.post('/add', (req, res) => {
const todoItem = req.body.todo;
todoList.push(todoItem);
res.json({success: true});
});
app.get('/list', (_, res) => {
res.json(todoList);
});
app.use((req, res, next) => {
res.status(404).send('404: Page not found');
});
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('500: Internal server error');
});
app.use(helmet());
app.use(compression());
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment