Cannot find module 'json-server'

See original GitHub issue

I’m following the guide in README.md and I encountered error Error: Cannot find module 'json-server' at Function.Module._resolveFilename (module.js:440:15) at Function.Module._load (module.js:388:25) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object.<anonymous> (/Users/amycheong/Desktop/remote-json-server/dev/server.js:1:80) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3)'

when I node server.js

I have installed json-server globally.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

49reactions
Nilegfxcommented, Feb 20, 2017

mmm … ok, try to install json-server locally (not globally)

  1. go to your server.js directory and run npm init -y
  2. npm install json-server --save-dev

You also could try:

  1. go to your server.js directory and run npm link json-server
  2. run node server.js

aside from that, I highly recommend you to change your global node_modules directory by setting an Environment variable NODE_PATH to /usr/lib/node_modules

export NODE_PATH=/usr/lib/node_modules

and then try to reinstall json-server (npm uninstall -g json-server && npm install -g json-server)

2reactions
Nilegfxcommented, Feb 20, 2017

I am assuming that you are missing a very very very simple and obvious step with I can’t guess, so I’ll write down the steps (sorry if it is super obvious for you) but just to make sure that we are in the same line.

  1. create a new directory (in your case I see you called it fake-server)
  2. copy the code snippet in server.js file
  3. run npm install -g json-server
  4. run node server.js

if you did the above and it is still not running, from the same directory that server.js file exist, run which json-serverand share the result of this command with us here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I resolve "Cannot find module" error using Node.js?
This error can be encountered if you are require ing a module that has a missing or incorrect main ...
Read more >
json-server - npm
Start using json-server in your project by running `npm i json-server`. There are 295 other projects in the npm registry using json-server.
Read more >
json-server: command not found error [Solved] | bobbyhadz
Use npx to solve the error "json-server: command not found", e.g. npx json-server --watch db. · Look at the PATH environment variable on...
Read more >
JSON Server (json-server) - DigitalOcean
You should have NPM installed on your machine. If not, then refer this post to install NPM. Below shows the one liner command...
Read more >
Solved: "Cannot find module 'x.json'" TypeScript Error
Find out why this TypeScript error happens and how to fix it ... This happens because TypeScript does not support resolving JSON files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found