Skip to content

Instantly share code, notes, and snippets.

@JacopoDaeli
Last active April 16, 2017 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacopoDaeli/c455f18579f05ccb8bd1242b09b5e124 to your computer and use it in GitHub Desktop.
Save JacopoDaeli/c455f18579f05ccb8bd1242b09b5e124 to your computer and use it in GitHub Desktop.
Say Hello {name} or Hello World.
'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