Advertisement
Guest User

Node Express App Boilerplate

a guest
Mar 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. const express = require('express')
  2. const app = express()
  3. app.use(express.static('public'))
  4. app.get('/', (req, res) => res.sendFile('index.html',{root: '.'}))
  5. app.get('/phaser3', (req, res) => res.sendFile('phaser3.html',{root: '.'}))
  6. app.get('/json/:type', (req, res) => {
  7. console.log(req.params.type)
  8. let data = {}
  9. switch(req.params.type){
  10. case "dog":
  11. data.name = 'Fido'
  12. data.sound = 'bark'
  13. break
  14. case "cat":
  15. data.name = 'Marissa'
  16. data.sound = 'meow'
  17. break
  18. default:
  19. data.name = 'NONAME'
  20. data.sound = 'NOSOUND'
  21. }
  22. res.send(data)
  23. })
  24. app.listen(3000, () => console.log('Example app listening on port 3000!'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement