Last active
April 16, 2017 01:56
-
-
Save JacopoDaeli/c455f18579f05ccb8bd1242b09b5e124 to your computer and use it in GitHub Desktop.
Say Hello {name} or Hello World.
This file contains hidden or 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
'use strict' | |
const express = require('express') | |
const app = express() | |
const PORT = process.env.PORT || 3000 | |
function capitalize (str) { | |
const firstLetter = str.charAt(0) // we can check what's inside here | |
return `${firstLetter.toUpperCase()}${str.slice(1)}` | |
} | |
app.get('/:name?', (req, res) => { | |
const name = req.params.name ? capitalize(req.params.name) : 'World' | |
res.send(`Hello ${name}!`) | |
}) | |
app.listen(PORT, () => console.log(`App listening on *:${PORT}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment