Unable to access ID keys and GET request

80 Views Asked by At

I can't access the db.json file id keys in the localhost port URL even though it should work.

I've downloaded the JSON Server node package on my Ubuntu via this code:

$ npm install -g json-server

I could start the server using the command json-server db.json but not json-server --watch db.json.

I can access the endpoint http://localhost:3000/articles but if I access the id keys http://localhost:3000/articles/1
The browser throws a 'Not found' error and the terminal throws me this error:

EtaError [Eta Error]: Could not find template: /home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/views/index.html
    at Eta.readFile (file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/eta/dist/eta.module.mjs:570:13)
    at Eta.handleCache (file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/eta/dist/eta.module.mjs:434:35)
    at Eta.render (file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/eta/dist/eta.module.mjs:460:30)
    at file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/lib/app.js:29:46
    at file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/@tinyhttp/app/dist/index.js:171:7
    at file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/@tinyhttp/app/dist/index.js:434:34
    at loop (file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/@tinyhttp/app/dist/index.js:437:81)
    at next (file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/@tinyhttp/app/dist/index.js:438:66)
    at file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/milliparsec/dist/index.js:25:9
    at file:///home/emilychew/.nvm/versions/node/v20.9.0/lib/node_modules/json-server/node_modules/@tinyhttp/app/dist/index.js:169:13

If I try to fetch a GET request, the active JSON server doesn't show the GET request in the terminal (as shown in picture)

db.json file content
Terminal and index,js code

Am I missing something?

I've tried reinstalling the JSON server package, but it is still the same.

0

There are 0 best solutions below