May 2018
Intermediate to advanced
492 pages
12h 3m
English
Now that we've implemented a REST-based server, we can return to the Fibonacci application, applying what we've learned to improve it. We will lift some of the code from fiboclient.js and transplant it into the application to do this. Create a new file, routes/fibonacci-rest.js, with the following code:
const express = require('express');const router = express.Router();const http = require('http');const math = require('../math');router.get('/', function(req, res, next) { if (req.query.fibonum) { var httpreq = http.request({ host: "localhost", port: process.env.SERVERPORT, path: "/fibonacci/"+Math.floor(req.query.fibonum), method: 'GET' }); httpreq.on('response', response => { response.on('data', ...Read now
Unlock full access