Express JS command is not working - node.js

After installing Express with Node.js using this command:
npm install -g express
I am not able to use the express command, I get thrown the error in windows that express is not an internal or external command.
I've checked to make sure Express was installed by using the command npm -g ls and express shows up in there like this:
C:\wamp\www\blackbook>npm -g ls
C:\Users\Chris\AppData\Roaming\npm
└─┬ express#4.0.0
├─┬ accepts#1.0.0
│ ├── mime#1.2.11
│ └── negotiator#0.3.0
├── buffer-crc32#0.2.1
├── cookie#0.1.0
├── cookie-signature#1.0.3
├── debug#0.8.0
├── escape-html#1.0.1
├── fresh#0.2.2
├── merge-descriptors#0.0.2
├── methods#0.1.0
├── parseurl#1.0.1
├── path-to-regexp#0.1.2
├── qs#0.6.6
├── range-parser#1.0.0
├─┬ send#0.2.0
│ └── mime#1.2.11
├─┬ serve-static#1.0.1
│ └─┬ send#0.1.4
│ ├── fresh#0.2.0
│ ├── mime#1.2.11
│ └── range-parser#0.0.4
├─┬ type-is#1.0.0
│ └── mime#1.2.11
└── utils-merge#1.0.0
Any ideas as to what I'm doing wrong or what I can do to fix it so I can use express?

I see you installed the latest Express.js version 4.0.0. In this version they removed the application generation from express itself. This is now a separated module called express-generator.
To install it, use the following command
$ npm install -g express-generator
To read more, check out the Express.js docs #executable

Related

express on alpine linux - creating express application fails

I'm trying to create a node js application on alpine linux.
I just did an
apk add nodejs
And now I just tried this command:
myserver:/var/www/widgets# npm install express -g
express#4.14.0 /usr/lib/node_modules/express
├── escape-html#1.0.3
├── utils-merge#1.0.0
├── cookie-signature#1.0.6
├── merge-descriptors#1.0.1
├── methods#1.1.2
├── fresh#0.3.0
├── path-to-regexp#0.1.7
├── vary#1.1.0
├── encodeurl#1.0.1
├── range-parser#1.2.0
├── parseurl#1.3.1
├── array-flatten#1.1.1
├── etag#1.7.0
├── content-type#1.0.2
├── cookie#0.3.1
├── content-disposition#0.5.1
├── serve-static#1.11.1
├── depd#1.1.0
├── qs#6.2.0
├── on-finished#2.3.0 (ee-first#1.1.1)
├── finalhandler#0.5.0 (unpipe#1.0.0, statuses#1.3.0)
├── debug#2.2.0 (ms#0.7.1)
├── proxy-addr#1.1.2 (forwarded#0.1.0, ipaddr.js#1.1.1)
├── accepts#1.3.3 (negotiator#0.6.1, mime-types#2.1.12)
├── type-is#1.6.13 (media-typer#0.3.0, mime-types#2.1.12)
└── send#0.14.1 (destroy#1.0.4, ms#0.7.1, statuses#1.3.0, mime#1.3.4, http-errors#1.5.0)
But when i try to then create an express application, I'm getting an error.
myserver:/var/www/widgets# express testapp
-ash: express: not found
myserver:/var/www/widgets#
I'm not sure what I need to do next.
Thanks.
The issue seems to be that you want to install the express-generator module:
$ npm install express-generator -g
Once you've done this, you can then use:
$ express myapp
To generate your new application, where myapp is the name of the application.
Source: Express application generator

Nodejs on Windows, npm doesn't install modules from registry

I'm having a problem with my new installation of Node.js (windows 64 bit).
I'm trying to install the express module inside a project of mine but I can't work it out.
I type this command :
npm install -g express
However this is the result of the command
├── escape-html#1.0.1 ├── merge-descriptors#0.0.2 ├── cookie-signature#1.0.5 ├── utils-merge#1.0.0 ├── cookie#0.1.2 ├── range-parser#1.0.2 ├── finalhandler#0.3.2 ├── fresh#0.2.4 ├── media-typer#0.3.0 ├── methods#1.1.0 ├── vary#1.0.0 ├── parseurl#1.3.0 ├── serve-static#1.7.1 ├── content-disposition#0.5.0 ├── path-to-regexp#0.1.3 ├── depd#1.0.0 ├── qs#2.3.3 ├── on-finished#2.1.1 (ee-first#1.1.0) ├── debug#2.1.0 (ms#0.6.2) ├── etag#1.5.1 (crc#3.2.1) ├── send#0.10.1 (destroy#1.0.3, ms#0.6.2, mime#1.2.11) ├── proxy-addr#1.0.4 (forwarded#0.1.0, ipaddr.js#0.1.5) ├── accepts#1.1.4 (negotiator#0.4.9, mime-types#2.0.4) └── type-is#1.5.4 (mime-types#2.0.4)
It's the list of dependecies needed by express but there's no download of them.
The first time I tried to use npm I had this problem (https://github.com/npm/npm/issues/4808)
There were many solutions to solve it, one of them consist in disable the layer ssl for the connection to the npm online registry but I don't think there's a connection between this solution (that I applied) and the problem.
Thank you in advance,
Luca
The express module should be installed on a per project basis.
npm install --save express

node.js ( how to create express)

lee-ui-MacBook-Pro:test1 ErinLee$ sudo npm install -g express
Password:
express#4.9.5 /usr/local/lib/node_modules/express
├── merge-descriptors#0.0.2
├── utils-merge#1.0.0
├── fresh#0.2.4
├── cookie#0.1.2
├── escape-html#1.0.1
├── range-parser#1.0.2
├── cookie-signature#1.0.5
├── finalhandler#0.2.0
├── vary#1.0.0
├── media-typer#0.3.0
├── parseurl#1.3.0
├── methods#1.1.0
├── serve-static#1.6.3
├── path-to-regexp#0.1.3
├── depd#0.4.5
├── qs#2.2.4
├── on-finished#2.1.0 (ee-first#1.0.5)
├── etag#1.4.0 (crc#3.0.0)
├── proxy-addr#1.0.3 (forwarded#0.1.0, ipaddr.js#0.1.3)
├── accepts#1.1.1 (negotiator#0.4.8, mime-types#2.0.2)
├── send#0.9.3 (destroy#1.0.3, ms#0.6.2, mime#1.2.11)
├── type-is#1.5.2 (mime-types#2.0.2)
└── debug#2.0.0 (ms#0.6.2)
lee-ui-MacBook-Pro:test1 ErinLee$ express
-bash: express: command not found
lee-ui-MacBook-Pro:test1 ErinLee$ express test1
-bash: express: command not found
lee-ui-MacBook-Pro:test1 ErinLee$
what's wrong?? why i can't create express??
i'm in terminal on mac os X
express is a node.js module.
You are looking for the express generator:
npm install -g express-generator
https://github.com/expressjs/generator

Does NPM load certain modules after it is installed (for its own use)?

I had some issues with NPM so I decided to simply uninstall Node, NPM & NVM and then reinstall everything on Mac OS X 10.8. After following various guides and Stackoverflow questions I was pretty sure I had gotten rid of everything. But to my surprise after I first installed NVM and then Node (which installed NPM for me) I couldn't understand why running npm -g ls shows lots of different modules which, after looking them up on the NPM registry, look to be very basic helpers and boilerplate modules which other more advanced modules build on. Here is the entire list of modules it prints out:
unknownd8a25e8b001d:~ [username]$ npm -g ls
/Users/[username]/.nvm/v0.10.18/lib
└─┬ npm#1.3.8
├── abbrev#1.0.4
├── ansi#0.1.2
├── archy#0.0.2
├── block-stream#0.0.7
├── child-process-close#0.1.1
├── chmodr#0.1.0
├── chownr#0.0.1
├── cmd-shim#1.0.1
├── editor#0.0.4
├── fstream#0.1.24
├─┬ fstream-npm#0.1.5
│ └── fstream-ignore#0.0.7
├── github-url-from-git#1.1.1
├── glob#3.2.6
├── graceful-fs#2.0.0
├── inherits#2.0.0
├── ini#1.1.0
├─┬ init-package-json#0.0.11
│ └── promzard#0.2.0
├── lockfile#0.4.0
├── lru-cache#2.3.0
├─┬ minimatch#0.2.12
│ └── sigmund#1.0.0
├── mkdirp#0.3.5
├── node-gyp#0.10.9
├── nopt#2.1.2
├─┬ npm-registry-client#0.2.28
│ └── couch-login#0.1.18
├── npm-user-validate#0.0.3
├─┬ npmconf#0.1.2
│ └─┬ config-chain#1.1.7
│ └── proto-list#1.2.2
├── npmlog#0.0.4
├── once#1.1.1
├── opener#1.3.0
├── osenv#0.0.3
├─┬ read#1.0.5
│ └── mute-stream#0.0.4
├── read-installed#0.2.3
├─┬ read-package-json#1.1.1
│ └─┬ normalize-package-data#0.2.1
│ └── github-url-from-git#1.1.1
├─┬ request#2.25.0
│ ├── aws-sign#0.3.0
│ ├── cookie-jar#0.3.0
│ ├── forever-agent#0.5.0
│ ├─┬ form-data#0.1.0
│ │ ├── async#0.2.9
│ │ └─┬ combined-stream#0.0.4
│ │ └── delayed-stream#0.0.5
│ ├─┬ hawk#1.0.0
│ │ ├── boom#0.4.2
│ │ ├── cryptiles#0.2.2
│ │ ├── hoek#0.9.1
│ │ └── sntp#0.2.4
│ ├─┬ http-signature#0.10.0
│ │ ├── asn1#0.1.11
│ │ ├── assert-plus#0.1.2
│ │ └── ctype#0.5.2
│ ├── json-stringify-safe#5.0.0
│ ├── mime#1.2.10
│ ├── node-uuid#1.4.0
│ ├── oauth-sign#0.3.0
│ ├── qs#0.6.5
│ └── tunnel-agent#0.3.0
├── retry#0.6.0
├── rimraf#2.2.2
├── semver#2.1.0
├─┬ sha#1.2.1
│ └── readable-stream#1.0.2
├── slide#1.1.4
├── tar#0.1.18
├── uid-number#0.0.3
└── which#1.0.5
So my question is, does NPM install various global modules for its own use when it is installed? It does look, from the indenting, as though these are modules npm uses because they're nested underneath npm#1.3.8 and with Finder I can see how NPM looks to have these within its own node_modules folder.
The Node Package Manager (NPM) itself is a module, which yes, does have dependencies. Therefore the answer to your question is yes, except that the modules are installed as dependencies, not globally. The module NPM itself is the global module.

npm: how are dependencies managed?

I installed express, mongodb, and mongoose.
This is the result of my npm ls:
/home/merc/Bookings
├─┬ connect-mongo#0.1.9
│ └─┬ mongodb#0.9.9-8
│ └── bson#0.0.4
├─┬ express#3.0.0rc2
│ ├── commander#0.6.1
│ ├─┬ connect#2.4.2
│ │ ├── bytes#0.1.0
│ │ ├── formidable#1.0.11
│ │ ├── pause#0.0.1
│ │ └── qs#0.4.2
│ ├── cookie#0.0.4
│ ├── crc#0.2.0
│ ├── debug#0.7.0
│ ├── fresh#0.1.0
│ ├── methods#0.0.1
│ ├── mkdirp#0.3.3
│ ├── range-parser#0.0.4
│ └─┬ send#0.0.3
│ └── mime#1.2.6
├─┬ jade#0.27.2
│ ├── commander#0.6.1
│ └── mkdirp#0.3.0
├─┬ mongodb#1.1.2
│ └── bson#0.1.1
└─┬ mongoose#3.0.0
├── hooks#0.2.1
├─┬ mongodb#1.1.2
│ └── bson#0.1.1
└── ms#0.1.0
You can clearly see that for some reason Jade is on the root directory (I assume this happened when I run "express". But then again, "mongodb" is available in different versions (0.9.9 and 1.1.2) and so is bson (0.1.1 and a worrying 0.0.4).
Hence my questions: how are dependencies managed with npm? Does every package simple install whatever they like, whichever version they pick?
I guess the question is: is this kind of duplication "normal", and "by design" so to speak?
Merc.
The short answer is, yes, this is by design. When you require a module from the node_modules directory, it uses the top-level directory--e.g., whichever one you specify in your package.json.
Other packages have their own package.json files, and are free to use whatever versions they want, and when they require them down in their own code, they will use their own node_modules folder.
Ideally, the modules you use have tests, etc. that ensure that versions (or even specify a range of versions, such as 0.9.x) of dependencies they specify work well, and seeing older versions of sub-dependencies in there doesn't necessarily mean danger, although new versions of these modules could of course potentially fix bugs and so forth. It may be worth finding a module you're concerned about on GitHub, downloading the repository, updating the package.json and dependencies yourself and running the tests to see if a new version works. If so, perhaps the author would be willing to accept a pull request with your update.

Resources