typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
73.05k stars 7.02k forks source link

i can't run this command $ npx json-server db.json #1479

Closed Anubhav22still closed 10 months ago

Anubhav22still commented 10 months ago

it shows : --watch/-w can be omitted, JSON Server 1+ watches for file changes by default undefined:1

SyntaxError: Unexpected end of JSON input at JSONFile.parse () at JSONFile.read (file:///C:/Users/anubh/AppData/Roaming/npm/node_modules/json-server/node_modules/lowdb/lib/adapters/node/DataFile.js:17:31) at async Observer.read (file:///C:/Users/anubh/AppData/Roaming/npm/node_modules/json-server/lib/observer.js:21:22) at async Low.read (file:///C:/Users/anubh/AppData/Roaming/npm/node_modules/json-server/node_modules/lowdb/lib/core/Low.js:16:22) at async file:///C:/Users/anubh/AppData/Roaming/npm/node_modules/json-server/lib/bin.js:85:1

Node.js v18.15.0

please help

typicode commented 10 months ago

Check the content of db.json, there seem to be a syntax error

Anubhav22still commented 10 months ago

my db.json is empty, I need to create localhost:3000 to test api for my project with this .

typicode commented 10 months ago

File can't be empty, copy this in your db.json and edit it with the resources for your project:

{
  "posts": [
    { "id": "1", "title": "a title" },
    { "id": "2", "title": "another title" }
  ],
  "comments": [
    { "id": "1", "text": "a comment about post 1", "postId": "1" },
    { "id": "2", "text": "another comment about post 1", "postId": "1" }
  ],
  "profile": {
    "name": "typicode"
  }
}
GabilAmanullayev1 commented 10 months ago

same problem

typicode commented 10 months ago

Try updating to latest version

A1eksD commented 6 months ago

Hey, i tried it with a small JSON and it worked after i distributed ID's. Hope it helps you. ps: i use Node.js v21.6.1