Skip to content

Instantly share code, notes, and snippets.

@slutske22
Last active December 24, 2021 22:24
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 slutske22/7dc0822b93dd55592bc6324e80afacac to your computer and use it in GitHub Desktop.
Save slutske22/7dc0822b93dd55592bc6324e80afacac to your computer and use it in GitHub Desktop.
Simple express server
import express from 'express';
import {
simpleCalculation,
complexCalculation
} from './utils'
// Set up app
const app = express();
const port = process.env.PORT ?? 8080;
// Set up routes
const router = express.Router();
router.get('/api/simple', (req, res) => {
const result = simpleCalculation();
res.json(result);
});
router.get('/api/complex', (req, res) => {
const result = complexCalculation();
res.json(result);
});
app.use('/', router);
// Start server
const server = app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment