'express' is not executable - node.js

This is quite basic. Many examples show terminal commands such as: 'express name-of-directory-to-be-created'. Yet on my system, though I've installed node.js (and command: node -v works, and npm -v works), command: express fails with: command not found Further investigation shows that, on my macbook air, all incidences of express.js are not executable. I believe express was installed using npm express or npm -g express. Please, what is going on? Are the examples correct? ( There are several, all from various sources. ) How may I execute
express directory
Thanks in advance.

This usually happens on windows.
You need to install express globally and the location where npm modules get installed should be added to PATH(environment variable).
To install express globally type npm install -g express
Also it looks like you are trying to use express-generator.If yes you should install it similarly.
npm install -g express-generator
In windows by default npm modules are installed at "C:\Users\u_name\AppData\Roaming\npm"
Edit your PATH environment variable and append your npm path at the end.

Related

Mac OS X, Node is installed by Nvm, but can't use module which is installed globally

The operation system is Mac OS X, After installing Node by using NVM, Node -v shows 9.2. And after installing express globally(npm install -g express), I cannot use express in the command line. If it is used, it will prompt that the module is not defined. Using npm root -g to find the installation of node path, in the lib or bin directory I can see the global installation of the package, but I can't be able to add lib or bin directory in the environment path, because there is no executable file in these two directories.
Any suggestions are very helpful, thanks.
The command-line program express is not installed with npm install express, no matter the command line parameters passed to it. To use the command line utility, you must globally install the package express-generator, like this:
npm install -g express-generator
You also should probably install normal express to your individual project, and not globally

Path of the express

Why express command not found. Here is the path for express.
/usr/lib/node_modules/express
When I install the express, the terminal shows the path. I used
npm install -g express-generator
npm install -g express
But when I run express, it doesn't work. In this directory, express is globally right? But why can't be found. I don't understand the logic.
You need to install express locally, rather than globally.
http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation
In general, the rule of thumb is:
If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
Based on this, you want to install express-generator using the -g flag as you will use it as a command line tool, but you want to install express without this flag as it's a module you will want to require() it in your application.
Take a look at the installation guide:
http://expressjs.com/starter/generator.html
It says to install the express-generator module as a global module as you will use it as a command line utility to scaffold your new applications.
Once you have scaffolded an application using the express myapp command, you just have to run npm install in the myapp directory which will download the rest of the dependencies to your projects local ./node_modules directory. It does this by reading the contents of the generated package.json file.
Lesson to take away: Don't install with the -g flag unless the modules instruction guide explicitly says to do so.

Node express command not found

i have used npm install -g express.
then used npm install -g express-generator
but when after install , i type express-V still told me :-bash: express: command not found.
please help me how to figure out this problem
You Say "Bash" that mean that you are running under linux or something similar. If a command could not be found from the system, it is not in in the Path environment variable. Check your NPM installation regarding environment variables. You need to include the global modules folder of npm in your Path.
Thanks for your answer.i reset the path environment and then it has been figured out.

Globally instaling packages doesn't work (node.js, npm)

For example I installed express with global (-g) parameter. In node.js/node_modules folder express doesn't exists.
I tried to install it without global parameter and it works perfectly.
How to install it globally?
Thanks.
Installing modules via npm with -g is only for modules that provide command-line utilities, not for making any ordinary module accessible from anywhere.
So if you are looking to use the command-line express project generator utility/command, you need to use npm install -g express-generator instead.
If you want to require('express'); in your application, then you need to install express with npm install express.

express not installed on my machine

I downloaded node.js onto my linux fedora core 18 machine.
After that using npm -g install express installed express. The problem is I am unable to find the express file to be supplied to Nodeclipse in the preference.
Hence, my application using express is not able to compile saying express not found.
Am I missing anything here?
try installing it with this command and see if it works:
npm install -g express
then go to cd myapp
npm link express
this could do the trick..
Nodeclipse is using express executable only for wizard. Everything else works as for node.js from command line (try node myapp.js)
As advised by #isaacs in Express module not found when installed with NPM, do npm install express for local project folder.

Resources