I would like to write a simple http server for testing my REST API's.I have chosen node js as my programming language to write the server. I have written very simple code. Below is my http server
var express = require('express')
var app = express();
var http = require('http')
var server = http.createServer(app);
server.listen(8080,function(){
console.log(' server listening on port ' +'8080');
})
app.post('/api/device/register', function(req, res) {
var mess="Registration Successful";
res.set({
'Content-Type': 'application/json',
'Content-Length': mess.length
});
res.status(200).send({
"status": 1,
"message": mess
});
});
Before testing REST API's ,I tested my server using postman client. Request and response are exchanged successfully.Postman client uses HTTP 1.1. and uses connection:Keep-alive as header and my server also responds with Connection:Keep alive. BUt after 200 OK ,my http server sends tcp FIN and after a while postman client responds and the connection is closed.
Not sure is this behavior is expected. My requirement is to keep the connection persistent ,so that client can send multiple requests to server. How can i achieve this?
Im using node 8.9.4 version and npm 5.6.0