Skip to content

Instantly share code, notes, and snippets.

@athiththan11
Created June 12, 2020 19:05
Show Gist options
  • Save athiththan11/54af57401ebae218925d7c366c3282d1 to your computer and use it in GitHub Desktop.
Save athiththan11/54af57401ebae218925d7c366c3282d1 to your computer and use it in GitHub Desktop.
Mock HTTP Socket NodeJS
{
"name": "socket-http",
"version": "1.0.0",
"description": "a simple http socket server",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "athiththan11",
"license": "ISC"
}
@hostname = localhost
@access-token = 1234567890
### Sample Request
curl -k GET http://localhost:3000
var http = require('http');
http.createServer(onReq).listen(3000);
function onReq(req, res) {
var socket = res.socket;
socket.write(
[
'HTTP/1.1 200 OK', // '{"Message":"No DATA"}HTTP/1.1 200 OK'
'Content-Type: application/json; charset=UTF-8',
'Content-Encoding: UTF-8',
'Accept-Ranges: bytes',
'Connection: keep-alive',
].join('\n') + '\n\n'
);
socket.write('{"hello": "world"}');
socket.end();
}
console.log('Mock server started on port 3000 !!!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment