Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

it doesn't work on xxx.js or remote url,though xxx.json is ok #1543

Open
nillwyc opened this issue Apr 29, 2024 · 0 comments
Open

it doesn't work on xxx.js or remote url,though xxx.json is ok #1543

nillwyc opened this issue Apr 29, 2024 · 0 comments

Comments

@nillwyc
Copy link

nillwyc commented Apr 29, 2024

it doesn't work on xxx.js or remote url,though xxx.json is ok

does anyone have the same problem as mine?

my Node.js:v18.19.0

this is a .js file in my work folder.

module.exports = () => {
  const data = { users: [] };
  // Create 1000 users
  for (let i = 0; i < 1000; i++) {
    data.users.push({ id: i, name: `user${i}` });
  }
  return data;
};

i tested these codes which copied on https://github.com/typicode/json-server/tree/v0
but something wrong

(base) PS T:\router> json-server --version
1.0.0-alpha.23

(base) PS T:\router> json-server http://jsonplaceholder.typicode.com/db
File http://jsonplaceholder.typicode.com/db not found

(base) PS T:\router> json-server --watch db.js
--watch/-w can be omitted, JSON Server 1+ watches for file changes by default
undefined:1
module.exports = () => {
^

SyntaxError: Unexpected token m in JSON at position 0
    at JSONFile.parse (<anonymous>)
    at JSONFile.read (file:///T:/myDev/env/nvm1.1.10/v18.19.0/node_modules/json-server/node_modules/lowdb/lib/adapters/node/DataFile.js:17:31)
    at async Observer.read (file:///T:/myDev/env/nvm1.1.10/v18.19.0/node_modules/json-server/lib/observer.js:21:22)
    at async Low.read (file:///T:/myDev/env/nvm1.1.10/v18.19.0/node_modules/json-server/node_modules/lowdb/lib/core/Low.js:16:22)
    at async file:///T:/myDev/env/nvm1.1.10/v18.19.0/node_modules/json-server/lib/bin.js:114:1

Node.js v18.19.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant