Express command not working in terminal - node.js

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

Related

'express' is not recognized as an internal or external command

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!

Express command not found after setting installing globally

When I run sudo npm install -g express-generator:
/Users/myname/npm/bin/express -> /Users/myname/npm/lib/node_modules/express-generator/bin/express-cli.js
/Users/myname/npm/lib
└── express-generator#4.15.5
And when I run express:
express not found
Also, I thought it was interesting that when I run which npm:
/usr/local/bin/npm
That is the path.
It seems that whenever I try to install something like yeoman or this express generator globally, it never works.
It should also be noted that I am on an Mac running zsh.
Most likely your npm bin directory is not in the path. Try to list the files in that directory by ls -l /usr/local/share/npm/bin/.
If you find the express file, you can add that directory to the path by export PATH=/usr/local/share/npm/bin:$PATH. If not, most likely something went wrong with your installation and you can try installing the module again.
Running this in the command line:
export PATH=/usr/local/bin/npm:$PATH
Fixed the issue...for now. I'm not totally sure why that worked.
This affects Homebrew users using Node.js & npm
When you install Node.js using Homebrew it does not put npm on the PATH for you, however it suggests that you should do so.
Homebrew doesn't modify the user's environment or dotfiles. However, brew install node does print a message suggesting the user add that path to their PATH.
Source

Node http-server not working on Ubuntu linux

I am trying to run a simple http server in my project directory. All I need is GET request support, so I can GET html/css/js/etc.
For that I wanted to use http-server from npm.
I installed it with npm install http-server -g
Now I cd to my project folder where it has the index.html file, I open the terminal and run http-server
But when I open my browser at http://localhost:8080/index.html - it can't connect to the host.
Am I missing something?
Okay, the issue was - I had another package installed on Ubuntu, which is also called node
Node JS package is called nodejs on my system and I think that http-server is looking specifically for 'node'.
In order to work around this:
I removed the node package with sudo apt-get remove node and created a symlink for nodejs:
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
First install npm.
Second npm install http-server -g.Next append after the http-server url template url like http-server C:\xampp\htdocs\

Trying to create an Express app at the command line

I have Ubuntu 13.10 and I installed Node.js using:
sudo apt-get install nodejs
I then installed Express using:
sudo npm install -g express
I had to use sudo for the express installation because I got errors when I tried to do it without.
The problem is when I try to create an express app or even type express -v at the command line nothing happens i.e.:
kwal0203#Kanes-laptop:~$ express -v
kwal0203#Kanes-laptop:~$
I can see the express files have been installed in the usr/local/lib/node_modules/express directory and the is also a file named express in the usr/local/bin/ directory which I assume is some type of shortcut or link or something.
Any ideas on why express is not working?
Thanks any help appreciated!
The solution was simply to install the nodejs-legacy package:
sudo apt-get install nodejs-legacy

Express doesn't work on ubuntu

I'm new with nodejs and trying to learn it. I have installed node framework express as global module by command:
$ sudo npm install express -g
This works correctly and I have it in /usr/lib/node_modules. Then I'm creating a new project on express:
$ express app
But this doesn't create project folder and does not return any error code, clear node code works fine. Anybody knows how to detect and fix this error?
found it. the npm package is actually named express-generator
sudo npm install -g express-generator
you can then use
express mytestapp
that results in :
olivier#****:~/workspace$ express mytestapp
create : mytestapp
create : mytestapp/package.json
create : mytestapp/app.js
create : mytestapp/public
create : mytestapp/public/javascripts
create : mytestapp/public/stylesheets
create : mytestapp/public/stylesheets/style.css
create : mytestapp/routes
create : mytestapp/routes/index.js
create : mytestapp/routes/users.js
create : mytestapp/views
create : mytestapp/views/index.jade
create : mytestapp/views/layout.jade
create : mytestapp/views/error.jade
create : mytestapp/bin
create : mytestapp/bin/www
create : mytestapp/public/images
install dependencies:
$ cd mytestapp && npm install
run the app:
$ DEBUG=my-application ./bin/www
Cheers !
Olivier
Source : http://expressjs.com/guide.html#executable
For me the solution was simply to install the nodejs-legacy package:
sudo apt-get install nodejs-legacy
First thing to try is if the plugin is installed:
$ npm -g ls | grep express
If nothing is returned, try reinstalling it.
Since in this case it was still installed, the next solution was to reinstall Node entirely.
There is a great post on cleaning up Node installations here: Uninstall Node.JS using Linux command line?
This is what I did to get mine to work and make sure everything was working ok on Ubuntu 12.04 running Node 0.8.21 and Express 3.2.0.
First install express
sudo npm install –g express
Now check that express is working by querying it for the version:
express -V
Now I went and created an express app:
cd /usr/lib/node_modules
sudo express -s -e expressTestApp
The following was output:
create : expressTestApp
create : expressTestApp/package.json
create : expressTestApp/app.js
create : expressTestApp/public
create : expressTestApp/public/javascripts
create : expressTestApp/public/images
create : expressTestApp/public/stylesheets
create : expressTestApp/public/stylesheets/style.css
create : expressTestApp/routes
create : expressTestApp/routes/index.js
create : expressTestApp/routes/user.js
create : expressTestApp/views
create : expressTestApp/views/index.ejs
install dependencies:
$ cd expressTestApp && npm install
run the app:
$ node app
So, following the instructions it gave me, I ran the following two commands in sequence:
cd expressTestApp
sudo npm install
After just a minute it finished and I was able to open /urs/lib/node_modules/app.js and work with it. Also, running node app like it said in the instructions during the express module creation worked as well.
From a previous comment, it looks like you might have fixed it by reinstalling node, but I still hope this will help you.
Perhaps a sudo express app might do the trick? (I see you're executing in /var/www, which generally is off limits from regular users?)
As of Ubuntu 16.04 LTS, the problem occurs when express is installed globally. To fix this, make sure you install express to your working directory even if you have installed globally.
Use
sudo npm i express-generator --save
to save it to your working directory in every project you do.
Had this problem and fixed it easily, without having to reinstall nodejs or any other dependency.

Resources