Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 586 Bytes

File metadata and controls

24 lines (20 loc) · 586 Bytes

Section 29.1: Sample node.js server that just handles POST requests

'use strict';

const http = require('http');
const PORT = 8080;

const server = http.createServer((request, response) => {
  let buffer = '';
  request.on('data', chunk => {
    buffer += chunk;
  });

  request.on('end', () => {
    const responseString = `Received string ${buffer}`;
    console.log(`Responding with: ${responseString}`);
    response.writeHead(200, "Content-Type: text/plain");
    response.end(responseString);
  });
}).listen(PORT, () => {
  console.log(`Listening on ${PORT}`);
});