Express Web Server

Overview


Simple Example





const express = require('express')
const bodyParser = require('body-parser')
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
	extended: false
})); 
const app = express()
const port = 80

app.get('/index.html', (req, res) => {
  res.send(`Hello World`);
});

app.get('/data,json', (req, res) => {
  let data = [1,2,3,4,5];
  res.send(JSON.stringify(data));
});
  
app.listen(port, () => {
  console.log(`listening on port`+port.toString());
})
					


HTTP Post






app.post('/data,json', (req, res) => {
  let data = [1,2,3,4,5];
  let args = req.body.args;
  res.send(JSON.stringify(data));
});
  
					


Topics


  • SSL - provides some simple code for enabling SSL on an express web server
  • Tokens - deomstrates how to modity the above web server to accept davinci authentication tokens.

Contents