Questions tagged [json-server]

json-server allows you to rapidly create a REST API server that delivers JSON data.

json-server is a tool written in that allows you to rapidly create a server that when started up, delivers json data via a API.

You can use json-server for rapid prototyping and mocking out other REST API services.

Supply a JSON file to describes the JSON data and the API that will deliver it and json-server will start up a server that provides that data via a REST API

Source Code and further documentation https://github.com/typicode/json-server

Installation npm install json-server

Egghead Video (free) Nodejs: Creating demo apis with json-server

477 questions
3
votes
1 answer

How to access nested resources in JSON server

I am trying to use json-server for my application. My json file goes like this: { "Categories": [ { "item": [ { "id": 1, "product_id": 1, "description": "Pizza1", "price": 12.99, …
Monkey
  • 55
  • 1
  • 6
3
votes
1 answer

React Multiple Fetch from state

so I am trying to fetch my SWAPI json-server twice using the homeworld id to get the homeworld name but I just get "TypeError: Cannot read property 'name' of undefined". Im fairly new to React so if it looks messy im sorry! Thanks in advance! import…
Tolby Hunt
  • 61
  • 1
  • 2
  • 4
3
votes
2 answers

I got an error when loading db.json

When I enter this command sudo json-server db.json I got this error: /usr/local/lib/node_modules/json-server/src/cli/utils/load.js:31 data = low(source, { storage: fileAsync }).state() …
Trung Nguyen
  • 51
  • 2
  • 4
2
votes
1 answer

Why am I getting an 404 Error from my POST request?

Using a form I'm adding purse information to the JSON server. I can see the data I entered in the debugger as I step through the code but it ends with an error below. I have no idea why, if it gets the data I'm getting 404 "file not found". I load…
2
votes
3 answers

Running Angular Application and JSON-Server With Same Startup Script

I have a requirement to run both my angular application and JSON-server simultaneously when I run "ng serve" or "npm run start", rather than having to start each one separately. How do I modify the startup scripts to do so? Note: This is running in…
Jason
  • 3,943
  • 12
  • 64
  • 104
2
votes
1 answer

npm start json-server in background

I'm trying to have my npm start script run json-server in the background in parallel to then running react-scripts to start UI. How would I go about doing this? I've tried various things with single & and prestart, etc but everything results in…
simonfanz
  • 31
  • 4
2
votes
1 answer

React form data submission to an api doesn't show changes in ui

I am working on a simple react app that takes a todo title via a form, and submits to my own API created with json-server package. My code is working so far but, after submitting the data I have to reload the app to show the changes. Now my question…
mSaif
  • 33
  • 4
2
votes
1 answer

How to dockerize json-server?

I'm trying to run json server with docker along with my application in react, but it's not working. My dockerfile and compose settings: FROM node:16-alpine WORKDIR /app COPY package*.json . RUN npm install COPY . . EXPOSE 3000 CMD [ "npm", "run",…
2
votes
1 answer

Custom POST with json-server, request.body === undefined

I am using https://github.com/typicode/json-server to mock data for a project. I have set up the server according to the documentation, but when creating a custom POST request, using curl: curl…
ghovmand
  • 23
  • 5
2
votes
0 answers

Question about watching multiple files with json-server

I followed the best solution below: can't watch multiple files with json-server db.js var firstRoute = require('./jsonfile1.json'); var secondRoute = require('./jsonfile2.json'); module.exports = function() { return { firstRoute :…
2
votes
1 answer

Can't redirect traffic to localhost with nginx and docker

I'm new to Docker and nginx so this may be a simple question but I've been searching through question/answers for a while and haven't found the correct solution. I'm trying to run an nginx server through docker to reroute all requests to…
Efie
  • 1,430
  • 2
  • 14
  • 34
2
votes
0 answers

how to execute two servers with a single command in angular

I was working on one angular project. I was using JSON server to host the data. and to run, I use ng serve -o. and to run json server, I use json-server -p 3500 db.json. instead of using two terminals, Is there anyway I can run ng serve -o and…
WhiteShadow
  • 431
  • 2
  • 5
2
votes
0 answers

Use middleware only for json server specific routes

How can I use a middleware ONLY FOR my json-server specific routes? In the json-server docs, I can see the following instructions: const jsonServerRouter =…
Rashomon
  • 5,962
  • 4
  • 29
  • 67
2
votes
0 answers

How to map the id parameter of the json-server onto a custom name

I am using the npm module json-server to simulate a simple REST-interface. As I am planning to customize its functionality a little bit, I am starting an express server and define the json-server as a middleware. The json-server reads its response…
Luk
  • 1,009
  • 2
  • 15
  • 33
2
votes
0 answers

json-server : how to do complex queries

I have a set of users each with a team id. I have a set of records which are 'owned' by a user. e.g. users: [ { id: 1, teamId: 1234 }, ... ], records: [ { id: 1, usersId: 1 }, .... ] Can I issue an API call to json-server that either gets all…
vogomatix
  • 4,856
  • 2
  • 23
  • 46