9951 explained code solutions for 126 technologies


nodejsHow to get request header in HTTP server


const http = require('http');

const server = http.createServer((req, res) => {
  res.end( req.headers['x-test'] );
});

server.listen(82, '127.0.0.1');ctrl + c
require('http')

import module to work with http protocol

http.createServer

creates HTTP server

(req,

object with request data

res

object to manage response

.end(

finished http response with given content

req.headers

object with all request headers

x-test

sample request header to get value of