I installed express, and it worked just fine:
...
npm http 200 https://registry.npmjs.org/send/-/send-0.1.4.tgz
npm http GET https://registry.npmjs.org/fresh/0.2.0
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/fresh/0.2.0
npm http GET https://registry.npmjs.org/fresh/-/fresh-0.2.0.tgz
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/range-parser/-/range-parser-0.0.4.tgz
npm http 200 https://registry.npmjs.org/fresh/-/fresh-0.2.0.tgz
npm http 200 https://registry.npmjs.org/range-parser/-/range-parser-0.0.4.tgz
express#4.0.0 /usr/local/lib/node_modules/express
├── methods#0.1.0
├── parseurl#1.0.1
├── merge-descriptors#0.0.2
├── utils-merge#1.0.0
├── escape-html#1.0.1
├── debug#0.8.0
├── cookie-signature#1.0.3
├── range-parser#1.0.0
├── fresh#0.2.2
├── qs#0.6.6
├── buffer-crc32#0.2.1
├── cookie#0.1.0
├── path-to-regexp#0.1.2
├── type-is#1.0.0 (mime#1.2.11)
├── send#0.2.0 (mime#1.2.11)
├── accepts#1.0.0 (mime#1.2.11, negotiator#0.3.0)
└── serve-static#1.0.1 (send#0.1.4)
But then i do:
express testapp
-bash: express: command not found
It's as if express is not installed. What's up with that?
Just FYI, i have OSX if that makes any difference?
The new version of Express (4.0) does not itself have a bin folder. You have to install express-generator to get the setup functionality.
Express 4.0 made significant changes. Specifically, moving middlewares and helpers into external modules.
If you need to get something up and running right away, you should install Express 3 and then learn how to get Express 4 running when you have more time.
First, make sure you have ./node_modules/.bin in your $PATH. Then...
npm install "express#3.x"
express
Or if you have time to learn the differences in Express 4 then you can get up and running by installing express-generator.
npm install express-generator
express
IMPORTANT: make sure you have ./node_modules/.bin in your shell $PATH variable. Executable files in Node modules are linked in the ./node_modules/.bin directory. Having that in your path makes it easy to run those executables without typing the whole path and without adding them globally. Adding them globally is a bad idea if you work with multiple projects and need to maintain backwards compatibility with old projects.
TIP: You can find the list of Express middlewares and helpers on Github.
Here is how I got my express app to work. I first ran
npm install -g express-generator
Then I created my app with
express app_name
Where app_name is obviously the name of your app.
Then I installed the dependancies.
cd app_name && npm install
Then to run the app I did
DEBUG=app_name ./bin/www
The prompts were generated by the system and you can copy and paste them. Then you visit
http://localhost:3000/
Here is my app working locally
Related
I wanted to install the latest version of socket.io, and the latest ver seems to be 1.45.socket.io download
To do this, I just type the following command.
npm install socket.io
However, when I checked installed modules in my laptop, socket.io's version did not change as can be seen below.
YANAGISAWAYUMA-no-MacBook-Pro:~ yanagisawa_yuma$ npm list --depth=0
yanagisawa_yuma#0.0.0 /Users/yanagisawa_yuma
├── ar-drone#0.3.3 extraneous (git://github.com/felixge/node-ar-drone.git#228bd4573e765bed3861f259ce7e66fcace15f43)
├── express#4.9.0
├── gulp#3.9.0
├── node#0.0.0
├── node-osc#1.1.0 extraneous
├── node-static#0.7.3
├── socket.io#1.1.0
└── static#2.0.0
What am I missing?
Instead of simply npm install socket.io,
try npm install socket.io#version
I'm working on a OSX 10.10.4, I have worked with node.js and express before on this computer.
But now when I want to start a new application, the computer won't recognize the command express anymore.
I've tried installing it with all these commands:
- npm install express
- npm install -g express
- npm install express -g
- sudo npm install -g express
- sudo npm install express -g
- npm install express-generator
- npm install -g express-generator
- npm install express-generator -g
- sudo npm install -g express-generator
- sudo install express-generator -g
- sudo npm install -g express-generator#3
- sudo npm install -g express-generator#4
But it still doesn't recognize the command express
This is the output when I install without the -g
npm install express
express#4.13.3 node_modules/express
├── escape-html#1.0.2
├── merge-descriptors#1.0.0
├── cookie#0.1.3
├── array-flatten#1.1.1
├── utils-merge#1.0.0
├── cookie-signature#1.0.6
├── methods#1.1.1
├── fresh#0.3.0
├── range-parser#1.0.2
├── vary#1.0.1
├── path-to-regexp#0.1.7
├── content-type#1.0.1
├── etag#1.7.0
├── parseurl#1.3.0
├── content-disposition#0.5.0
├── serve-static#1.10.0
├── depd#1.0.1
├── qs#4.0.0
├── finalhandler#0.4.0 (unpipe#1.0.0)
├── on-finished#2.3.0 (ee-first#1.1.1)
├── debug#2.2.0 (ms#0.7.1)
├── proxy-addr#1.0.8 (forwarded#0.1.0, ipaddr.js#1.0.1)
├── type-is#1.6.6 (media-typer#0.3.0, mime-types#2.1.4)
├── accepts#1.2.12 (negotiator#0.5.3, mime-types#2.1.4)
└── send#0.13.0 (destroy#1.0.3, statuses#1.2.1, ms#0.7.1, mime#1.3.4, http-errors#1.3.1)
and when I install with the -g
sudo npm install -g express-generator
Password:
/Users/Maiteh/.node/bin/express -> /Users/Maiteh/.node/lib/node_modules/express-generator/bin/express
express-generator#4.13.1 /Users/Maiteh/.node/lib/node_modules/express-generator
├── sorted-object#1.0.0
├── commander#2.7.1 (graceful-readlink#1.0.1)
└── mkdirp#0.5.1 (minimist#0.0.8)
I have tried some other stuff like the PATH and nodejs-legacy, but none of them work.
With the sudo apt-get install nodejs-legacy the computer doesn't find the command apt-get.
The reason I got express:command not found after I installed was because my $PATH didn't know where express was.
To anyone wanting to install the express command line tools I did this
sudo npm install express-generator -g
which resulted in
/usr/local/share/npm/bin/express -> /usr/local/share/npm/lib/node_modules/express-generator/bin/express
express-generator#4.13.1 /usr/local/share/npm/lib/node_modules/express-generator
├── sorted-object#1.0.0
├── commander#2.7.1 (graceful-readlink#1.0.1)
└── mkdirp#0.5.1 (minimist#0.0.8)
when I tried express --version I got a command not found
Open your bash_profile from terminal with open ~/.bash_profile
After that add the path you got after you installed express, in my case it was
/usr/local/share/npm/lib/node_modules/express-generator/bin/express
Add this to your bash_profile
export PATH=/usr/local/share/npm/lib/node_modules/express-generator/bin:$PATH
Save the file and go back to terminal. Enter hash -r and then quit terminal and start it again.
Now if you try express --version for example you should see that the command line tools are working.
There's kind of a mishmash of problems you're describing here, so I'll try to address them one at a time.
Express is a popular framework for node.js. The typical way to add it to your project is to do npm install --save express and then it will save it into your package.json file and install it into node_modules. Adding -g to that command would attempt to install it globally, but that's not how express is used. Express is used on a per-project basis. See their website for details.
In the big list of commands you've run, you mention express-generator. Express-generator is a tool that lets you quickly build out some boilerplate to make starting an express project a bit easier. Since express-generator is meant to be run globally and not inside a project, you DO install it with the -g flag. See their website for details on use and installation.
You're trying to install some more node stuff with the apt-get command. That command is used for package management on Linux (typically Ubuntu/Debian) machines. Mac OS X doesn't come with it (and you absolutely don't need it). Any instructions that mention running apt-get are not targeted towards Mac users.
Essentially, I don't think you have a problem, the logs you show are exactly what I'd expect to see. Generate a boilerplate project with express-generator and you should be all set to start working on your express project. Good luck!
js on my windows 7 machine, i have executed the below commands from
C:\node> npm install -g express -generator
and also C:\node> npm install -g express -generator#4, and also the npm link express
for the above commands, i got the below messages.
express#4.10.7 C:\Users\user1\AppData\Roaming\npm\node_modules\express
├── methods#1.1.1
├── finalhandler#0.3.3
├── cookie-signature#1.0.5
├── serve-static#1.7.2
├── merge-descriptors#0.0.2
├── utils-merge#1.0.0
├── range-parser#1.0.2
├── media-typer#0.3.0
├── cookie#0.1.2
├── content-disposition#0.5.0
├── parseurl#1.3.0
├── vary#1.0.0
├── escape-html#1.0.1
├── fresh#0.2.4
├── path-to-regexp#0.1.3
├── depd#1.0.0
├── qs#2.3.3
├── on-finished#2.2.0 (ee-first#1.1.0)
├── etag#1.5.1 (crc#3.2.1)
├── debug#2.1.1 (ms#0.6.2)
├── type-is#1.5.5 (mime-types#2.0.7)
├── accepts#1.1.4 (negotiator#0.4.9, mime-types#2.0.7)
├── send#0.10.1 (destroy#1.0.3, ms#0.6.2, mime#1.2.11, on-finished#2.1.1)
└── proxy-addr#1.0.4 (forwarded#0.1.0, ipaddr.js#0.1.5)
and with npm link express:
C:\node\node_modules\express -> C:\Users\user1\AppData\Roaming\npm\node_modul
es\express
but still when i execute the express nodetest1 at C:/node> i am getting the express is not recognized error.
anyone know any pointers would be helpful.
You have a space between express and -generator above... if this was copy-pasted, maybe you missed it... it's supposed to be express-generator as a single unit.
Make certain that %USERPROFILE%\AppData\Roaming\npm both exists and is in your PATH environment variable... If it isn't there, you will have to open a new prompt after adding it. Some versions of node's installer don't always create or add it correctly.
If you are using [nvm for windows] you will need to ensure that C:\Program Files\nodejs is in your path (the installer should work correctly), you'll need to run nvm via command prompt Run as Administrator. This is because nvm uses symbolic links from the global install path to a specific version under your profile to run against.
I've been using nvm for windows for a few months now (switching from 0.10.x and 0.11.x versions) and it's been a bit easier to work with.
Make sure you are runing the command promt as System Administrator "This is very important", then do npm install -g express after that chang to the directory where you want to create your app and you are good to go. NB if you are using express 4 then install it via npm install -g express-generator#4
I was following along to this tutorial about setting up an express app. But when I ran node app.js the server would not start. The previous command that I ran was
cd express_example && npm install
But I got this error
npm WARN engine express#4.9.8: wanted: {"node":">= 0.10.0"} (current: {"node":"0.8.4","npm":"2.1.4"})
npm WARN engine void-elements#1.0.0: wanted: {"node":">=0.10.0"} (current: {"node":"0.8.4","npm":"2.1.4"})
So i thought that it was because a newer version of node was necessary. So I looked at the version of node that I had, noticed it was older so I tried upgrading. But when I ran brew update node i got this alert.
Error: node-0.10.32 already installed
I did some searching around and found this answer here on SO. Which suggested running these commands
sudo npm cache clean -f
then
sudo npm install -g n
then
sudo n stable
But the server still wont startup. But at least I am now at v0.10.33
I also found this similar question on SO whose accepted answer said to try sudo node app.js but that just does not seem right, nor did it even work.
If you are using Express 4 and using the generator, there is a slightly diffrent method for running the app. Express 4 changed the file structure to:
├── app.js
├── bin
│ └── www
├── package.json
├── public
│ ├── images
│ ├── javascripts
│ └── stylesheets
│ └── style.css
├── routes
│ ├── index.js
│ └── users.js
└── views
├── error.jade
├── index.jade
└── layout.jade
Notice the bin/www directory.
The app start logic is now seperated in the bin/www file. Therefore you have to run your app with the following command:
DEBUG=<<app_name>> ./bin/www
Reference: http://expressjs.com/starter/generator.html
I tried to install gulp by
npm install -g gulp
The output seems to be something like this. (i have skipped some logs)
npm http 304 https://registry.npmjs.org/string_decoder
npm http 304 https://registry.npmjs.org/lodash._htmlescapes
/usr/bin/gulp -> /usr/lib/node_modules/gulp/bin/gulp.js
gulp#3.6.2 /usr/lib/node_modules/gulp
├── tildify#0.2.0
├── pretty-hrtime#0.2.1
├── deprecated#0.0.1
├── archy#0.0.2
├── semver#2.2.1
├── chalk#0.4.0 (has-color#0.1.7, ansi-styles#1.0.0, strip-ansi#0.1.1)
├── orchestrator#0.3.3 (sequencify#0.0.7)
├── liftoff#0.9.8 (extend#1.2.1, minimist#0.0.8, resolve#0.6.3, findup-sync#0.1.3)
├── vinyl-fs#0.1.4 (graceful-fs#2.0.3, map-stream#0.1.0, mkdirp#0.3.5, vinyl#0.2.3, glob-stream#3.1.9, glob-watcher#0.0.6)
└── gulp-util#2.2.14 (lodash._reinterpolate#2.4.1, dateformat#1.0.7-1.2.3, minimist#0.0.8, vinyl#0.2.3, multipipe#0.0.2, through2#0.4.1, lodash.template#2.4.1)
In the above script i can see a line
/usr/bin/gulp -> /usr/lib/node_modules/gulp/bin/gulp.js
which i guess is making a simulink in bin folder. So i should be getting gulp globally but i get the this error.
No local gulp install found in /var/www/ksapp
Any idea why i am getting this error.
Thanks
As pointed out in the doc, you should install it globally (you did that) and add it to your project dev deps (locally):
npm install gulp --save-dev
I faced the same issue. Got it resolved by creating a link
npm link gulp
Check /home/username/.npm directory: maybe groups/owner of files is root. Change to username:
chown -R username.username /home/username/.npm
I've recently run into the "Local gulp not found" error message. I was able to work past it by creating a symlink from the global node_modules directory to the local project directory where my gulpfile.js is located.