Last updated: Apr 28, 2023
Reading time·4 min
The error "npm should be run outside of the Node.js REPL, in your normal
shell" is shown when you try to run an npm
command from the Node.js REPL.
To solve the error, press Ctrl
+ D
to exit the REPL and run the npm
command in cmd
(Windows) or bash
(macOS and Linux).
Here is the complete error message.
Welcome to Node.js v20.0.0. Type ".help" for more information. > npm install axios npm should be run outside of the Node.js REPL, in your normal shell. (Press Ctrl+D to exit.) >
If you open a shell (e.g. CMD, PowerShell, bash or zsh) and type node
, you
start the Node.js REPL (read, evaluate print loop).
If you have a REPL session started, you can exit it by pressing Ctrl
+ D
or
(Cmd
+ D
on macOS).
Once you exit the REPL session, you can run your npm
command, e.g.
npm --version
.
You can also exit the Node.js REPL by pressing Ctrl
+ C
twice or by typing
.exit
and pressing Enter
.
Notice that there is a period before the word "exit", the command is .exit
.
Once you exit the Node REPL, you can issue your npm
command, e.g.
npm --version
or npm install axios
.
npm --version npm install axios
Make sure to replace axios
with the name of the module you're trying to
install.
The REPL is meant to run Node.js programs not npm
commands.
You have to run npm
commands in your normal shell.
For example, if you are on Windows:
npm
command.npm --version npm install axios
If you try to install a module globally in CMD, you might get a permissions error.
Here is an example command that installs the pm2
module globally.
npm install -g pm2
If you get a permissions error, you have to start CMD as an administrator and rerun the command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
npm install -g pm2
If you are on Windows, you can also use PowerShell.
npm
commands.npm --version npm install axios
If you try to install a module globally in PowerShell, you might get a permissions error.
Here is an example command that installs the pm2
module globally.
npm install -g pm2
If you get a permissions error, you have to start PowerShell as an administrator and rerun the command.
Click on the Search bar and type PowerShell.
Right-click on the PowerShell application and click "Run as administrator".
npm
command.npm install -g pm2
I've also written articles on:
If you are on macOS or Linux, run npm
commands in your default shell, e.g.
bash
or zsh
.
npm --version npm install axios
Make sure to replace axios
with the name of the module you're trying to
install.
If you try to install a module globally in bash or zsh, you might get a permissions error.
Here is an example command that installs the pm2
module globally.
npm install -g pm2
If you get a permissions error, prefix the command with sudo
.
sudo npm install -g pm2
You can learn more about the related topics by checking out the following tutorials: