'express' is not recognized as an internal or external command - node.js

I am trying to start an express-generator app but I am getting "express is not recognized an internal or external command. I tried all the below
in windows CMD as administrator:
$ npm install express -g
$ npm install express-generator -g
$ mkdir myApp
$ cd myApp
$ express helloApp
the latest command was supposed to create all the express-generator related files (i.e. routes, models, views, etc.). But I am still getting the same error again and again. Any solutions would be much appreciated.

Since you are using npm < v8.2.0 you need to install it globally (v8.2.0 allows you to use npx). From their documentation:
$ npm install -g express-generator
$ express --view=pug myApp
You can change the view parameter or even exclude it. This is how I always do it and I just tested it to confirm it works for me although I am using a different version of npm and node than you are.

try this.
npm cache clear --force
$ npm install -g express-generator
$ mkdir myApp
$ cd myApp
$ express helloApp `
remember if you are installing globally you need to use sudo for linux and mac, and powershell or admin cmd to run the code. eg
$ sudo npm install -g express-generator

i solved the above error by uninstalling node js(v10.16.3) and reinstalling the current version (v12.12.0) ....followed by the known commands:
npm install express -g
npm install express-generator -g
express project_folder_name
honestly till now i couldn't find any reason for what caused this...but i suppose it was something related to my node_modules directory....
thanks Dillan and Ani for your kind help...your suggestions helped a lot....thanks :)

One other possibility - I was unable to use express-generator in vscode. I tried to use it separately in both cmd and powershell. It worked using cmd, but not powershell. Modify vscode to make cmd the default terminal and you're good!

Related

Is it possible to run a node.js CL app without using the global folder?

I would like to know whether it is possible somehow to run a node.js command line app without using the global folder, i.e. no npm install -g or npm link.
If you want to use a cli that is npm installed locally without using anything else, you can do (assuming webpack):
node ./node_modules/.bin/webpack
Just check that directory ./node_modules/.bin
Probably npx would work for you.
$ npm i -D webpack
$ npx webpack ...

getting error when using -g in npm

when I try to install any package globally, I get multiple errors. have a look at the image
the errors in the terminal
Thanks all.
When you install any global package just add sudo prefix. sudo npm install -g express
If you want to install packages globally with the "g"-parameter you must be root.
It's easy to just run sudo npm install -g express to successfully install express.
But a long time solution for the permission access, run chown -R YOUR_USERNAME /usr/lib/node_modules from your terminal so that you will not have to include sudo in your subsequent installation using -g

Nodemon installed but can't be found

I've tried uninstalling and and reinstalling nodemon several times both locally and globally with:
npm install -g nodemon
(tried it both with and without sudo)
and it seems to install no problem, and gives me:
/usr/local/bin/bin/nodemon -> /usr/local/bin/lib/node_modules/nodemon/bin/nodemon.js
/usr/local/bin/lib
└── nodemon#1.11.0
but whenever I run
nodemon server.js
in my app, I get;
-bash: nodemon: command not found
Like I mentioned, I've tried the same process but installing locally to my app dependancies, but it doesn't seem to make a difference. What's going on here? I followed the same process on a different machine, and it worked no problem.
Googling around, I came across some posts that mentioned changing/adding the PATH? But it's not clear to me if that's or the problem or what that means.
Also, other globally installed npm modules run just fine
nodemon is not being found by bash.
Edit your ~/.bash_profile file and add:
PATH=$PATH:/usr/local/bin/bin/
Start a new shell to see it work, or run source ~/.bash_profile to have it apply to the current session.
Instead of using sudo switched as root and then just run:
$ npm install -g nodemon
sudo su -
export PATH=$PATH:/home/USER/npm
npm install -g --force nodemon
# THESE LINES + START FROM A NEW TERMINAL...
# IN MY CASE
npm install -g --force node-inspector
# TOO

Cannot run ionic. receives "No command 'ionic' found"

I want to start using the ionic framework, but unfortunately I'm already failing on the first step.
I am running Ubuntu 13.04 and I have node v0.10.25 installed.
I've installed ionic, at described in their docs:
sudo npm install -g cordova
sudo npm install -g ionic
The installation went well, no errors or warnings, but after the installation I type
ionic
and I get the error:
No command 'ionic' found, did you mean:
Command 'ionice' from package 'util-linux' (main)
Command 'sonic' from package 'sonic' (universe)
ionic: command not found
I'm pretty new to ubuntu so I might have something not configured correctly, but I can't find what.
Thanks
for some of you, the two answer above might not work. here's a more general solution for situation where you see "XX" command not found
first check your npm root and npm root -g
the result for the npm root -g should be something like "/usr/local".
if it's not, then you found your problem.
change it by:
npm config set prefix /usr/local
then npm root -g should give you something like /usr/local/lib/node_modules
.
Then go ahead re-install everything with -g
you will be good to go!
Well, I found it finally.
The ionic installation was at /home/guy/npm/bin/ionic, not at /usr/bin/ionic at it should be.
Solved it with:
sudo ln -s /home/guy/npm/bin/ionic /usr/bin/ionic
I solved the problem by cd to my root. Then install ionic as root admin.
$ sudo npm install -g cordova ionic
then run
$ ionic
to see if it's working.
Someone might run into this after trying to change the global library directory of npm to a folder they have permissions to write to in order to be able to install global libs without root permissions.
In that case you might have forgotten to add the new folder to you PATH environment variable.
The whole process of fixing Permissions can be found here.
in case that source disappears here is a copy of the steps:
There are times when you do not want to change ownership of the
default directory that npm uses (i.e. /usr) as this could cause some
problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory
altogether. In our case, this will be a hidden directory in our home folder.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4 you can also use the corresponding ENV variable (e.g. if you don't want to modify
~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global npm install -g jshint
if you just follow these steps and reinstall all the Global libs there is a good chance that it will start working for you anyways...
Just remember that if you do this, you will save your global libs into the folder created in step 1 instead of the default location in /usr/local or just /usr (depending on your OS flavor i guess?)
First Solution
I recently ran into this issue and the only solution that worked for me was to uninstall both ionic and cordova.
npm uninstall -g cordova
npm uninstall -g ionic
Then just reinstall
npm install -g cordova
npm install -g ionic
Second Solution
I ran into this issue again! This time check your environmental variables.
Run npm bin -g and check if the path returned is in your environmental variables. For me, it prompted that it was not found in the terminal output. I added that path to the environmental variables and restarted the terminal. From there everything started to work again. (source)
I had the same problem with “bash: ionic: command not found”,
then I added:
%USERPROFILE%\AppData\Roaming\npm
to my environment variable’s path, then I reinstalled ionic and cordova and it start working.
For Mac users
1. install the ionic
npm i -g #ionic/cli
2. check npm path
npm root -g
3. copy full path of ionic
Ex. /usr/local/Cellar/node/15.2.1/lib/node_modules/#ionic/cli/bin
4. open this file as administrator "/etc/paths" with nano or whatever editor
Ex. sudo nano /etc/paths
5. Add ionic bin file full path to file ends. And save file.
That's it.
Run npm root -g, copy the result path and add it to the paths file:
sudo nano /etc/paths
Restart your console and it will work.
this worked for me. try adding below to the ~/.bash_profile for mac OSX el capitan users:
NPM_PACKAGES="${HOME}/.npm-packages"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
then run source ~/.bash_profile to reload the profile in terminal.
additional info: node v4.3.1
In my case, I have just uninstalled ionic and then reinstalled it. And it is working fine now.
I also faced same problem but i solved i used following commands on terminal it worked
sudo npm uninstall ionic
then i used
sudo npm install -g cordova ionic#latest
and it worked fine it automatically installs best stabel version of cordova and latest stable version of ionic . for me it installed ionic 3.7.0
and cordova 7.0.1
you can change temporary :
npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm\node_modules2
Run your command to install your package .
open file explorer copy the link C:\Users[username]\AppData\Roaming\npm\node_modules
ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.
copy your package file CMD to parent folder "npm"
copy your package folder to parent folder "node_modules"
now run npm config set prefix C:\Users[username]\AppData\Roaming\npm
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm
now package working correctly with Command line
=> this method working with me When npm block in installation Package for IONIC installation and ReactNative and another package npm.
The package name has changed from ionic to #ionic/cli!
To update, run: npm uninstall -g ionic
Then run: npm i -g #ionic/cli

Express command not working in terminal

I am kind of new to node.js. I installed node fine and it works. I can run the node command in the terminal as well as the node package manager command(npm). Working on a Mac by the way. So I installed express globally with the following command:
sudo npm install -g express
After I was done installing it globally I installed it in a small folder where I am working on a project.
sudo install express
That gave me a node_modules folder inside of my site folder. After I was done that I went to install stylus using the express command and I got the error that express is not a command.
express -c stylus
Can anyone shed some light on this issue? I also tried to link the global express to the folder where I am working on the project using the following command:
sudo npm link express
The terminal said that this command ran, but I still cannot run the express command.
Thanks for asking questions on this one. I found that running express-generator instead of just express fixed the problem. The following code in the terminal worked.
sudo npm install -g express-generator
Thanks again,
If your express binary keeps doing nothing. Install node-legacy:
sudo apt-get install nodejs-legacy
on ubuntu 14.04 nodejs 0.10 express did not work on terminal, though
sudo apt-get install nodejs-legacy
made it to work.
I faced similar issue. I tried all the solutions mentioned here. However couldn't get my problem solved.
This happens when location of express and nodejs is not same.
Issue arises when Node is installed using homebrew.
Just use this command export PATH=/usr/local/share/npm/bin:$PATH
NOTE: replace path with the path of express.
Follow this link for help.
Make sure you have package.json & index.js files. And instaled express-generator with -g tag.
If still getting error use like ex:npx express --view=pug myapp --git
I fixed this on my mac by forcing my user to own /usr/local/lib and running the command to install express-generator globally:
sudo chown -R $USER /usr/local/lib
then:
npm install -g express-generator
After this you can go ahead and run your express commands:
express -h

Resources