superserver
v0.0.6
Published
a dummy REST server for testing HTTP client
Downloads
10
Maintainers
Readme
Superserver
a dummy REST server for testing HTTP client
Installation
$ npm install superserver --global
CLI
Always returns by JSON.stringify the request
object of requestListener.
And add a summary of request: .originalUrl
, .query
,.body
,.data
.
$ superserver 8080
# Server running at http://localhost:8080/
$ curl http://localhost:8080/\?foo\=bar --data '{"baz":"beep"}' > request.json
request.json
{
"headers": {
"host": "localhost:8080",
"user-agent": "curl/7.43.0",
"accept": "*/*",
"content-length": "14",
"content-type": "application/x-www-form-urlencoded"
},
"url": "/?foo=bar",
"method": "POST",
"originalUrl": "http://localhost:8080/?foo=bar",
"query": {
"foo": "bar"
},
"body": "{\"baz\":\"beep\"}",
"data": {
"baz": "beep"
}
// ...
}
API
superserver.listen(port,callback)
superserver.close(callback)
Start the superserver on the specified port
import superserver from 'superserver'
const port= 59798
superserver.listen(port,()=>{
console.log('Server running at http://localhost:%s/',port)
})