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.
Related
How can I create dynamic routes in electron? I am confused because electron doesn't make use of URLs if am not mistaken
You have to use build in packages such as express. The command to install it is: npm install express --save (to install locally in the project directory) or npm install express -g to install it globally.
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.
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.
I am trying to install express module install, but the issue is that after installation I am still unable to use express.
What I've done:
Install express using cmd - npm install -g express
For some reason it's not installing globally.
Help?
You might want to use the following:
npm install -g express-generator
Source: Issues with installing Express.JS in Windows 7
In later versions of express comand line was migrated to a separate module: express-generetor
use
npm install -g express-generator#3
and could use the express command
I'm new in node js, I'm triying to install globally express
npm i -g express
all completes, but when I enter
express --help
it says that it's not inside or outside command, however when i enter supervisor it runs OK. I looked into pathof express and there is no any .cmd file. If the problem is that. How should i fix it?
Please help.
Installing npm install -g express will install express 4.
Express 4 separates the generator from express.
What you need to do is to run:
$ npm install -g express-generator
Then it will work.
As stated in express Readme [1], you need to install express generator separately, using following command:
npm install -g express-generator#3
[1] - https://github.com/visionmedia/express/blob/master/Readme.md