Возможно, вы могли бы использовать метод request.getHeader(name)
Я смотрел https://nodejs.org/api/http.html#http_request_getheader_name
Редактировать 1:
index. js
const http = require('http');
const server = http.createServer((request, response) => {
console.log(request.headers);
console.log(request.headers.authorization);
console.log('----');
const headers = {
'Content-Type': 'text/plain',
};
let statusCode = 404;
response.writeHead(200, headers);
response.end('Hi');
});
server.listen(8080, () => {
console.log(`Server listening on port :8080 ?`);
});
Выполнение в первом терминале:
node index.js
Второй терминал:
curl localhost:8080 -H 'authorization: hello'
Выход первого терминала:
{ host: 'localhost:8080',
'user-agent': 'curl/7.68.0',
accept: '*/*',
authorization: 'hello' }
hello
----