Json-server: Run json-server as teamcity build step

Created on 10 May 2016  路  2Comments  路  Source: typicode/json-server

More of a question rather than issue... have anyone tried to use json-server as part of their CI process?

I'm trying to run it locally within CI agent but cannot see how can I inform teamcity to continue to next build step (throw exit code 0 and do not show below welcome message) as currently it just sits there ...

  \{^_^}/ hi!

  Loading db.json
  Done

  Resources
  http://localhost:3004/posts

  Home
  http://localhost:3004

  Type s + enter at any time to create a snapshot of the database

Most helpful comment

It depends on what you want to do, what you need json-server for.

You may want to include the project as a module in your tests, so that when they end, json-server is stopped as well.

var jsonServer = require('json-server')
var server = jsonServer.create()
var router = jsonServer.router('db.json')
var middlewares = jsonServer.defaults()

server.use(middlewares)
server.use(router)
server.listen(3000, function () {
  console.log('JSON Server is running')
  // start tests
  // process.exit(0)
})

You could also spawn ./node_modules/.bin/json-server using child_process API and kill it when you don't need it anymore.

You can add --quiet to suppress output (but it you spawn it, you can simply set no output).

All 2 comments

It depends on what you want to do, what you need json-server for.

You may want to include the project as a module in your tests, so that when they end, json-server is stopped as well.

var jsonServer = require('json-server')
var server = jsonServer.create()
var router = jsonServer.router('db.json')
var middlewares = jsonServer.defaults()

server.use(middlewares)
server.use(router)
server.listen(3000, function () {
  console.log('JSON Server is running')
  // start tests
  // process.exit(0)
})

You could also spawn ./node_modules/.bin/json-server using child_process API and kill it when you don't need it anymore.

You can add --quiet to suppress output (but it you spawn it, you can simply set no output).

thanks @typicode, I found that my approach was perhaps wrong as I've tried to run json-server on separate build step and invoke the tests on the other... now both are merged and issue is gone

Was this page helpful?
0 / 5 - 0 ratings