0

ok ... first time I'm trying my hand at node.js.

installed it a while back, and not sure how i installed it.

last night, decided to tackle a tutorial regarding node.js and express.

checked my version of node which is v0.8.14 and npm which is 1.1.65. (I'm on Mac, 10.6.8 version)

but did this anyway

npm install -g express

seemed to go ok ... but whenever I tried to generate a new application via

express new ProjectName

I got this:

-bash: express: command not found

Decided to try

 sudo npm install express -g

which again seemed to go well ... but again, the express new ProjectName got the same statement.

tried again:

npm install -g express  

got a lot of errors unlike the first time.

npm WARN package.json application-name@0.0.1 No README.md file found!
AA-s-MacBook-Pro:express_node aa$ express new HotPie
-bash: express: command not found
AA-s-MacBook-Pro:express_node aa$ npm cache clean
AA-s-MacBook-Pro:express_node aa$ npm install -g express
npm http GET https://registry.npmjs.org/express
npm http 200 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/express/-/express-3.0.6.tgz
npm http 200 https://registry.npmjs.org/express/-/express-3.0.6.tgz
npm ERR! error rolling back Error: EPERM, chmod '/usr/local/share/npm/bin/express'
npm ERR! error rolling back  express@3.0.6 { [Error: EPERM, chmod '/usr/local/share   /npm/bin/express']
npm ERR! error rolling back   errno: 50,
npm ERR! error rolling back   code: 'EPERM',
npm ERR! error rolling back   path: '/usr/local/share/npm/bin/express' }
npm ERR! Error: EPERM, chmod '/usr/local/share/npm/bin/express'
npm ERR!  { [Error: EPERM, chmod '/usr/local/share/npm/bin/express']
npm ERR!   errno: 50,
npm ERR!   code: 'EPERM',
npm ERR!   path: '/usr/local/share/npm/bin/express' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 10.8.0
npm ERR! command "/usr/local/Cellar/node/0.8.14/bin/node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /Users/aa/Documents/express_node
npm ERR! node -v v0.8.14
npm ERR! npm -v 1.1.65
npm ERR! path /usr/local/share/npm/bin/express
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, chmod '/usr/local/share/npm/bin/express'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/aa/Documents/express_node/npm-debug.log
npm ERR! not ok code 0

and so it went on and on: errors ... or no errors. I'm at total loss. and online literature on fixing this problem seems rather sparse.

advice, please?

oh, also saw this somewhere online: (whatever it means)

/usr/local/share/npm/bin/express 

which resulted in this:

destination is not empty, continue? 
destination is not empty, continue? (yes or no) yes

   create : .
   create : ./package.json
   create : ./app.js
   create : ./public/javascripts
   create : ./public/images
   create : ./public/stylesheets
   create : ./public/stylesheets/style.css
   create : ./routes
   create : ./routes/index.js
   create : ./routes/user.js
   create : ./views
   create : ./views/layout.jade
   create : ./views/index.jade
   create : ./public

   install dependencies:
     $ cd . && npm install

   run the app:
     $ node app

so ... ??? any advice would be appreciated! (please also let me know if I left any pertinent information required)

1 Answers1

2

Sounds like you need to edit your path variable.

Edit your ~/.bash_profile. Add this export somewhere.

export PATH=/usr/local/bin:$PATH:/usr/local/share/npm/bin

What's happening is that node isn't setting up its PATH correctly. I've had this happen to me before. Its something they should fix.

You may not have a .bash_profile. In *nix systems, there are a few different files you can place in your home directory to add environment variables and such.

bash_profile is the one I prefer, so in the terminal cd to ~ and touch .bash_profile.

Then edit it via nano .bash_profile or whatever editor you like.

(In nano, control-o to save, control-x to exit.)

When you've added it, do: source .bash_profile

Then try which express and see if it shows the path.

Geuis
  • 41,122
  • 56
  • 157
  • 219
  • This is what I got: -bash: /Users/aa/.rvm/gems/ruby-1.9.3-p327@rails329/bin:/Users/aa/.rvm/gems/ruby-1.9.3-p327@global/bin:/Users/aa/.rvm/rubies/ruby-1.9.3-p327/bin:/Users/aa/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin: No such file or directory –  Jan 09 '13 at 20:12
  • um ... a couple of questions, if you don't mind. this won't affect the rvm or homebrew, right? and when i tried "open~/.bash_profile," it said it didn't exist. but if it didn't exist, how could i have come up with what I showed you? –  Jan 09 '13 at 20:25
  • hold on: just did "touch .bash_profile," and then "open .bash_profile" and this is what showed up in the file: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* –  Jan 09 '13 at 20:27
  • so, if I add your export PATH statement, it won't affect what showed up in the file, right? –  Jan 09 '13 at 20:28
  • ok ... added your export statement, did source, and then which express. this is what I got: /usr/local/share/npm/bin/express that's good, right? –  Jan 09 '13 at 20:38
  • um ... it doesn't seem to have worked ... when i tried "express New ProjectName", again it came up with -bash: express: command not found –  Jan 09 '13 at 20:40
  • Most indeedy. The source command reloads it in the context of your existing terminal session. Try closing the terminal and opening a new one. – Geuis Jan 09 '13 at 20:41
  • oh wow! just closed my terminal windows, and tried again "express new PracticeProject", and got all those create, create, etc. Yay, that means, it's working. (right?) –  Jan 09 '13 at 20:45
  • Should be. Give it a spin. If the engine starts knocking, just whack it with a wrench a couple times. – Geuis Jan 09 '13 at 20:47
  • thank you very much for taking the time out to respond to my original question, and the follow ups. much appreciated! just one more question and you probably won't be able to answer it anyway ... but how do you know when a problem you're having may have to do with path variable? –  Jan 09 '13 at 20:47
  • Hard-won experience, mainly. Have had this problem before and how to fix it. The main give-away was that Express was clearly installed. When you ran it directly via /usr/local/share/npm/bin/express it worked. So any time you can run a program via a direct path, but its global name isn't recognized, its a PATH problem. – Geuis Jan 09 '13 at 20:53
  • Thank you Geuis. =) And if the engine starts knocking, I'll try to whack it (and cross my fingers at the same time). =) –  Jan 09 '13 at 20:55
  • I have a somewhat unrelated problem, but not sure why it's happening. Everytime I do "express new ProjectName", and then try to cd into it, it says: "-bash: cd: ProjectName: No such file or directory". When I checked my folder, it shows a folder called new. For whatever reason, it's not naming it ProjectName. Any idea why? Let me know if you rather not answer this question. I'll create a new question. And hope this is not too much of an imposition! –  Jan 09 '13 at 21:36
  • oh never mind. Turns out that writing "express new ProjectName" creates a folder titled new. Whereas if I skip the word new, then the folder gets titled ProjectName. Thanks anyway! –  Jan 09 '13 at 21:42
  • Yup, just about to say that =) – Geuis Jan 09 '13 at 21:43
  • hm, seems the tutorial i'm following is a bit outdated i guess. oh well, i'm still sticking through it! =) –  Jan 09 '13 at 21:44