13

I have installed Node.js through the installer on their webpage and added it's path to my environment variable so I can use node and npm through the command line. If I make an express app, it works, but I have to create it manually.

This is fine I guess, but I was wondering why I can't use the express command? I am getting

`express` is not recognized as an internal or external command, operable program or batch file.

I noticed that express installs in C:\Username\node_modules instead of where I thought it would go, in C:\Program Files\Nodejs\node_modules. Is this a problem?

5 Answers 5

31

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

1
  • 2
    yes, actually, that is correct answer if you have already install by npm install express -g, -g can genrate modules folder, but didn't provide command of express, you need install generator for it, current version is 4. Jul 27, 2014 at 8:45
5

Although this is not necessarily a problem, it's annoying and and error is an error even if you can navigate around it.

Although you can reference other node modules even if they are not in the node directory, as far as I understand node requires the modules to be in the node_modules folder within the Nodejs directory in order to automatically find them. (I had a similar issue on osx and this method solved it.)

Try moving the contents of

C:\Username\node_modules into C:\Program Files\Nodejs\node_modules\

Alternatively,

You can also install modules globally with:

npm install express -g

which allows you to access them without having to worry about your node directory, although these are then more difficult to manage and "you should try to avoid if you can".

From the Node Blog:

Just like how global variables are kind of gross, but also necessary in some cases, global packages are important, but best avoided if not needed.

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.

Resources

4
  • Thanks! Thought I had done that but I moved them into C:\Program Files\Nodejs\npm\node_modules, not C:\Program Files\Nodejs\node_modules Jul 26, 2012 at 6:49
  • haha yeah it took a few tried for me aswell when i was going through this; I believe it's an issue with the installer as it installs to the current directory that it is pointing at not a set destination i.e Nodejs/node_modules Jul 26, 2012 at 6:52
  • I think you can install node modules globally with -g option: npm install -g modulename
    – Mariy
    Jul 26, 2012 at 7:02
  • I totally forgot about that, will add to my answer Jul 26, 2012 at 7:22
2

You should install the express globally.

npm install express -g
0
1

Installing node.js adds the C:\Users\\AppData\Roaming\npm\ directory to your PATH variable. If the global install is not working correctly then something must have accidentally removed it. Running a repair-install of node.js should fix this issue

0

Just want to add the following: instead of first installing it globally using:

npm install express -g

And then moving it, like the accepted answer says (which is just silly), just simply install it within node js:

npm install express

-g is for global, you want it locally so NodeJS can access it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.