typicode/json-server

POST failing when running json server via npm run

Open

#303 opened on Jun 9, 2016

View on GitHub
 (11 comments) (0 reactions) (0 assignees)JavaScript (75,566 stars) (7,285 forks)batch import
bughelp wanted

Description

I have json server configured to run conveniently using a npm-run-script like so npm run db.

{
  "name": "My App",
  "scripts": {
    "db": "json-server --watch db.json --port 3004"
  }
}

This works fine for all GET requests, however, fails for any POST request with the following stacktrace:

TypeError: _.maxBy is not a function
    at Function.createId (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/json-server/src/server/mixins.js:44:16)
    at Function.module.exports.insert (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/underscore-db/src/index.js:58:31)
    at baseWrapperValue (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/lodash/index.js:2768:30)
    at LodashWrapper.wrapperValue (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/lodash/index.js:6124:14)
    at LodashWrapper.<anonymous> (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/lowdb/lib/_index.js:76:19)
    at LodashWrapper.wrapper [as value] (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/lodash/index.js:3592:19)
    at create (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/json-server/src/server/router/plural.js:214:8)
    at Layer.handle [as handle_request] (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/express/lib/router/route.js:131:13)
    at next (/Users/hady.osman/Development/react-native/PeopleNote/node_modules/express/lib/router/route.js:125:14)

This is not a problem if I was to run the json-server command manually on the command line using the very same db.json that I have.

Seems like there is a problem with the scope that is used to run the script?

Contributor guide