User Tools

Site Tools


bwnjsejs:creating_routes
var express = require('express');

var app = express();

app.get('/', function(req, res) {
  res.send('<h1>๐Ÿ˜</h1><p>Hello !</p>')
})
app.get('/fr', function(req, res) {
  res.send('<h1>๐Ÿ˜</h1><p>Bonjour !</p>')
})

app.get('/who/:name?', function(req, res) {
  var name = req.params.name;
  res.send('<h1>๐Ÿ˜</h1><p>Hello ' + name + ' !</p>')
})

app.get('/who/:name?/:title', function(req, res) {
  var name = req.params.name;
  var title = req.params.title;
  res.send('<h1>๐Ÿ˜</h1><p>Hello ' + name + ' !</p><p>' + title + '</p>')
})

// si on a autre chose
app.get('*', function(req, res) {
  var name = req.params.name;
  var title = req.params.title;
  res.send('<h1 style="font-size:250pt">๐Ÿ˜ญ</h1>');
})

var server = app.listen(3000, function() {
  console.log('Listening on port 3000.');
})
bwnjsejs/creating_routes.txt ยท Last modified: 2016/05/08 15:23 by leo