'npm install -g json-server is not working on mac, giving error. What should I do

I am trying to install npm install -g json-server on mac OS, but it is showing error. Any recommendation. What I need to change ?



Solution 1:[1]

I am trying to do this and I am expecting db.json file, but it is giving error

Sagar-MacBook-Pro:~ admin$ npm install -g json-server

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/json-server npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules npm ERR! code EACCES npm ERR! syscall access npm ERR! path /usr/local/lib/node_modules/json-server npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/json-server' npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/json-server'] { npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/usr/local/lib/node_modules/json-server' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/admin/.npm/_logs/2021-07-15T19_14_44_727Z-debug.log Sagar-MacBook-Pro:~ admin$

Solution 2:[2]

Try adding 'sudo' at the beginning.

sudo npm install -g json-server

then enter admin password to begin install.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dhanashri Sonar
Solution 2 S.B