Created
July 21, 2017 01:38
-
-
Save nathabonfim59/5be224178fee18bd1a79edf6d1cf22cb to your computer and use it in GitHub Desktop.
FullStackAcademy - aula 1 - exercício 6
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
const express = require('express') | |
const app = express() | |
const porta = 3000 | |
// Redireciona o usuário para o a página de soma | |
app.get('/', (request, response) => { | |
response.send('Vá para <a href="/somar">Somar</a>') | |
}) | |
// Realiza a soma propriamente dita com base nas variáveis na URL | |
app.get('/somar', (request, response) => { | |
if (request.query) { | |
if (request.query.num1 && request.query.num2) { | |
response.send('A soma é: '+(Number(request.query.num1) + Number(request.query.num2))) | |
} else { | |
response.send('Digite os números na url. <br> <strong>Exemplo</strong><br>\ | |
O exemplo abaixo soma os algarismos 50 + 9, some os seus também!<br>\ | |
<a href="http://localhost:'+porta+'/somar?num1=50&num2=9">\ | |
http://localhost:'+porta+'/somar?num1=50&num2=9</a>') | |
} | |
} | |
}) | |
// Inicia o servidor na porta 3000 | |
app.listen(porta, () => console.log('O servidor está rodando em: http://localhost:'+porta)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho.