We're going to debug a small web server, so let's create that real quick.
On the command line, we execute the following commands:
$ mkdir app $ cd app $ npm init -y $ npm install --save express $ touch index.js future.js past.js
Our index.js file should contain the following:
const express = require('express') const app = express() const past = require('./past') const future = require('./future') app.get('/:age', (req, res) => { res.send(past(req.params.age, 10) + future(req.params.future, 10)) }) app.listen(3000)
Our past.js file should look like this:
module.exports = (age, gap) => { return `${gap} years ago you were ${Number(age) - gap}<br>` }
And our future.js file should be as follows:
module.exports = (age, gap) => {
return `In ${gap} years you will be ${Number(age) + gap}<br>`
}
Web frameworks
We're only using Express here as an example. To learn more about Express and other frameworks, see Chapter 7, Working With Web Frameworks.
We're only using Express here as an example. To learn more about Express and other frameworks, see Chapter 7, Working With Web Frameworks.