Last active
December 24, 2021 22:24
-
-
Save slutske22/7dc0822b93dd55592bc6324e80afacac to your computer and use it in GitHub Desktop.
Simple express server
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'; | |
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