I am new bee in json-server. How can i stop the json-server on my terminal.
ctrl + c :)
How does one kill the server if not using the CLI, for example if I'm requiring the module in a test file. My assumption is there should be a .stop() or .kill() method, similar to how .listen() starts the server.
@BenRKarl There is :) json-server is built on Express so you get access to all the usual methods of https://nodejs.org/api/http.html#http_class_http_server
var jsonServer = require('json-server')
var app = jsonServer.create()
// ...
var server = app.listen(3000)
// ...
server.close(function () {
console.log('closed')
})
Don't know what your tests look like, but I would recommend checking supertest, it makes testing Express servers very easy (it's used in the project).
You should add this to README.md @typicode.
Or I'll do a PR when I'm back at home.
@typicode I am new in NodeJS and I saw in the tutorial that he stopped the server and start it again without saying how he typed "^C". Thanks!
"^C" stand for ctrl + c :)
Running ^C returns me a message that says to update json-server and doesn't quit the server.
@baka-gaijin-hakka same for me.
but updating solves it :smile:
// close service (sometimes there are some delays)
server.close(function(err) {
// do something
});
// exit node process
process.exit()
// use module
www.npmjs.com/package/kill-port
Most helpful comment
ctrl + c:)