Routes

  • Simply specify which directory shows which files

The Code

var express = require('express');
var app = express();

var port = process.env.PORT || 3000;

app.get('/', function(req, res) {
    res.send('<html><head></head><body><h1>Hello world!</h1></body></html>');
});

//id is the variable the request
//is the url, you just use *localhost:3000/person/stanley *   no need to use ?= because this is not query string,
//just accessing variable in the route
//passing variables via the route

app.get('/person/:id', function(req, res) {
    res.send('<html><head></head><body><h1>Person: ' + req.params.id + '</h1></body></html>');
});

app.get('/api', function(req, res) {
    res.json({ firstname: 'John', lastname: 'Doe' });
});

app.listen(port);

results matching ""

    No results matching ""