Skip to content

Instantly share code, notes, and snippets.

@mykeels
Created April 6, 2018 12:25
Show Gist options
  • Save mykeels/48ac39144df03c0cf1499dc6b546cef5 to your computer and use it in GitHub Desktop.
Save mykeels/48ac39144df03c0cf1499dc6b546cef5 to your computer and use it in GitHub Desktop.
const express = require('express')
const textBodyParser = require('body-parser').text()
const isPrime = require('./is-prime')
const app = express()
app.post('/', textBodyParser, (req, res) => {
res.send(req.body.split('\n').map((line) => line.split('').reverse().join('')).join('\n'))
})
app.get('/', (req, res) => {
const primes = []
const max = Number(req.query.max) || 1000
for (let i = 1; i <= max; i++) {
if (isPrime(i)) primes.push(i)
}
res.json(primes)
})
app.listen(process.env.PORT || 3030)
console.log('app is running!')
module.exports = app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment