Simple server responds to any HTTP request with details about the request.
npminstall @streammedev/parrot-server;First, import the class:
importParrotServerfrom'@streammedev/parrot-server';Next, instantiate it:
constserver=newParrotServer();Next, start it:
server.start();
Your server is now accepting requests at http://localhost.
Once you're done, stop the server by calling stop, ie:
server.stop();constructor(port) - Instantiates a new server instance on the specified (optional) port. Whether it is set explicitly or not, server.port will be set to the port once the server has started.
start(cb) - Starts the server, then calls the (optional) callback.
stop(cb) - Stops the server, then calls the (optional) callback.
A simple cli command is available:
parrot-server --port=8080importParrotServerfrom'@streammedev/parrot-server';importassertfrom'assert';importrequestfrom'request';describe('do some test',function(){lettestServer;before(function(done){testServer=newParrotServer(port);testServer.start(done);});after(function(done){testServer.stop(done);});it('should get my endpoint',function(done){request('http://localhost/my-endpoint?q=findme',function(error,response,body){assert.ifError(error);assert.ifError(response.statusCode!==200);assert.strictEqual(body.method,'GET','it should be a GET request');assert.strictEqual(body.path,'my-endpoint','it should have the right path');assert.strictEqual(body.query.q,'findme','it should set the q query parameter');})})})}Contributions are welcome. Please see our guidelines in CONTRIBUTING.md