Sample node.js server that just handles POST requests

suggest change
'use strict';

const http = require('http');

const PORT = 8080;
const server = http.createServer((request, response) => {
  if (request.method !== 'POST') {
    response.writeHead(405, { 'Allow': 'POST', 'Content-Type': 'text/plain' });
    response.end('POST only');
    return;
  }

  let buffer = '';
  request.setEncoding('utf8');
  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}`);
});

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents