Json-server: quit the json-server

Created on 22 Jul 2015  路  9Comments  路  Source: typicode/json-server

I am new bee in json-server. How can i stop the json-server on my terminal.

Most helpful comment

ctrl + c :)

All 9 comments

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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pantchox picture pantchox  路  3Comments

sboudouk picture sboudouk  路  3Comments

TXRRNT picture TXRRNT  路  4Comments

strom picture strom  路  4Comments

bahmutov picture bahmutov  路  3Comments