Skip to content

Instantly share code, notes, and snippets.

@helton
Created July 20, 2017 02:48
Show Gist options
  • Save helton/ab4b56c370f400ddceab5c2302fe3bb0 to your computer and use it in GitHub Desktop.
Save helton/ab4b56c370f400ddceab5c2302fe3bb0 to your computer and use it in GitHub Desktop.
Full Stack Academy - Aula 01 - Exercicio 06
/*
* [Exercício 6]
* Utilizando o ExpressJS, crie uma rota que some 2 números enviados como
* parâmetros na URL. Exemplo, ao executar no navegador:
* http://localhost:3000/somar?num1=10&num2=30
* deverá ser retornado na tela A soma é: 40.
*/
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
if (req.query && req.query.num1 && req.query.num2) {
const soma = parseInt(req.query.num1) + parseInt(req.query.num2)
res.send(`A soma é: ${soma}`)
}
res.end()
})
app.listen(port, () => console.log(
`Servidor rodando na porta ${port}. Abra http://localhost:3000/?num10=1&num2=30 no seu navegador`
))
@tuliofaria
Copy link

Certinho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment