Getting Started with Express

I’m following Andrew Burgess’ instructions on how to install Express and I’m getting a terminal error… ‘Please try running this command again as root/Administrator.’ I got this same terminal error when following his instructions in tutorial Comparing Front-End Frameworks.
I googled it and got something on stack overflow:
So I entered two commands: the first one) npm -g ls | grep -v ‘npm@’ | awk ‘/@/ {print $2}’ | awk -F@ ‘{print $1}’ | xargs npm -g rm
and the second one) npm ls -gp | awk -F/ ‘/node_modules/ && !/node_modules.*node_modules/ {print $NF}’ | xargs npm -g rm

As I read on I discovered I may have blown off my npm on my mac. So I went to and insalled node v5.9.1 Stable … I got a dialog saying 'The installation was completed successfully. Node.js was installed at /usr/local/bin/node
npm was installed at /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.

So now following Andrew’s instructions 1.2 How to Install Express in his tutorial ‘Getting Started with Express’ I installed NODE.JS as I mentioned above, checked it in terminal:
LucillenneysMBP:expressApp lucillekenney$ node --version
LucillenneysMBP:expressApp lucillekenney$ npm --version

I did mkdir expressApp and cd expressApp
in ~/Desktop/expressApp
npm install express
I get :slight_smile:

LucillenneysMBP:expressApp lucillekenney$ npm install express
npm ERR! Darwin 14.5.0
npm ERR! argv “/usr/local/bin/node” “/usr/local/bin/npm” “install” "express"
npm ERR! node v5.9.1
npm ERR! npm v3.7.3
npm ERR! path /Users/lucillekenney/.npm/express/4.13.4
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/Users/lucillekenney/.npm/express/4.13.4’
npm ERR! at Error (native)
npm ERR! { [Error: EACCES: permission denied, mkdir ‘/Users/lucillekenney/.npm/express/4.13.4’]
npm ERR! errno: -13,
npm ERR! code: ‘EACCES’,
npm ERR! syscall: ‘mkdir’,
npm ERR! path: ‘/Users/lucillekenney/.npm/express/4.13.4’ }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/lucillekenney/desktop/expressApp/npm-debug.log
LucillenneysMBP:expressApp lucillekenney$

I don’t know what to do. I have to solve this in order to use the tutorials. I’m a front end person trying to learn frameworks but it seems installing them is a back end skill. I may need a better understanding of global vs local and where things get installed …

Any help with this would be appreciated. As I mentioned I did go into that Stack Overflow which suggested removing globals to get past the ‘Please try running this command again as root/Administrator.’

It looks to me like maybe the .npm folder in your home (/Users/lucillekenney) folder doesn’t exist. Or perhaps it has protected access somehow? It does seem like you have the right versions of Node and NPM installed, and that they are trying to download the files to the correct location (your user folder instead of a global system folder), but that they are getting an access error on the /Users/lucillekenney/.npm/express/4.13.4 folder.

Right. I have to fix the npm permissions. I have two options from the npm site …

Option 1: Change the permission to npm’s default directory
Option 2: Change npm’s default directory to another directory

I don’t know which one to do. The steps looks simple enough. I just don’t understand which would be better or best practice.

Since the directory is in your normal home directory, it should have the right permissions. But, if you ever ran npm with the sudo command, then some of the directories would have root permissions. To fix this, simply run:

sudo chown -R lucillekenney ~/.npm

That should make every directory in your home’s .npm directory be owned by you. Since all the errors above are due to permission issues, this should fix it.

OK … so basically I’m changing ownership over user local to me and the directories inside of it … Since this is my own machine, I think that would be the better way to go.

I think that would be better than changing my config prefix.

Thank you Richard and adam for helping me figure this out.

Holy cow! Now it’s -bash: mvim: command not found

I solved this one by just using vim so I was able to create the server.js

But now I’m getting when I type in node server.js I get this:
node server.js
throw err;

Error: Cannot find module 'express’
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object. (/Users/lucillekenney/server.js:1:77)
at Module._compile (module.js:413:34)
at Object.Module._extensions…js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)

I suppose I’m getting that because I got this when installing: npm install express body-parser

├── serve-static@1.10.2
├── utils-merge@1.0.0
└── vary@1.0.1
npm WARN enoent ENOENT: no such file or directory, open '/Users/lucillekenney/desktop/template/package.json’
npm WARN template No description
npm WARN template No repository field.
npm WARN template No README data
npm WARN template No license field.

Uh oh I did this:

sudo npm cache clean && \

sudo npm install -gf yo &&
sudo npm install -gf express

and then after I put my password in, I got this:

npm WARN using --force I sure hope you know what you are doing.
npm WARN deprecated npmconf@2.1.2: this package has been reintegrated into npm and is now out of date with respect to npm
/usr/local/bin/yo -> /usr/local/lib/node_modules/yo/lib/cli.js

yo@1.7.0 postinstall /usr/local/lib/node_modules/yo

" I sure hope you know what you are doing." ??? Oh my !!! exactly what I was afraid of … I don’t know what I’m doing!!!

I got a little further … I have the server set up but I’m getting an error in localhost:3000

Error: ENOENT: no such file or directory, stat '/Users/lucillekenney/template/public/index.html’
at Error (native)

Hmm… I’d stay away from the --force / -f flag. I think if a command does’t work without forceing it, it’s probably not going to work.

Anyway, there’s a lot going on in this thread and it’s a little hard to know where you’re at or what your question is. Last error message says that there is no public/index.html file. Does that file exist? Do you expect the server to be looking somewhere else for an index file?

Hi Adam, At that point localhost:3000 was working and I had just created the server.js file per the tutorial. In that file was the path to public but apparently it was missing from my setup.

I’ve since run > npm install -g npm
and now localhost:3000 says This site can’t be reached

I’m not sure what to do at this point. Since I don’t thoroughly understand how to address the errors as they happen, I have to google them and try whatever I find.

I did make a backup before I started all of this but I wouldn’t know which files to replace or if that’s even worth it. Can I replace those files by just physically moving them from my backup to my usr folders? Or do I need to go through an uninstall and start over? I’m not sure what to do.

What about starting your project again in a fresh folder? Leave all the NPM installation stuff alone and just create the project files the same way Andrew does in the video and see if it works. If you’re sure you have the same project code as Andrew, then you could post the error and we can try and see if there is something wrong with your NPM install.

OK, do I need to delete the old ‘template’ folder via terminal or can I just drag it to the trash?

No, you can just trash it.

I trashed the ‘template’ folder and started over.

The third step was npm install express body-parser and I got an error in the terminal:

├─┬ body-parser@1.15.0
│ ├── bytes@2.2.0
│ ├─┬ http-errors@1.4.0
│ │ └── inherits@2.0.1
│ ├── iconv-lite@0.4.13
│ ├── qs@6.1.0
│ └─┬ raw-body@2.1.6
│ └── bytes@2.3.0
└─┬ express@4.13.4
├─┬ accepts@1.2.13
│ ├─┬ mime-types@2.1.10
│ │ └── mime-db@1.22.0
│ └── negotiator@0.5.3
├── array-flatten@1.1.1
├── content-disposition@0.5.1
├── content-type@1.0.1
├── cookie@0.1.5
├── cookie-signature@1.0.6
├─┬ debug@2.2.0
│ └── ms@0.7.1
├── depd@1.1.0
├── escape-html@1.0.3
├── etag@1.7.0
├─┬ finalhandler@0.4.1
│ └── unpipe@1.0.0
├── fresh@0.3.0
├── merge-descriptors@1.0.1
├── methods@1.1.2
├─┬ on-finished@2.3.0
│ └── ee-first@1.1.1
├── parseurl@1.3.1
├── path-to-regexp@0.1.7
├─┬ proxy-addr@1.0.10
│ ├── forwarded@0.1.0
│ └── ipaddr.js@1.0.5
├── qs@4.0.0
├── range-parser@1.0.3
├─┬ send@0.13.1
│ ├── destroy@1.0.4
│ ├── http-errors@1.3.1
│ ├── mime@1.3.4
│ └── statuses@1.2.1
├── serve-static@1.10.2
├─┬ type-is@1.6.12
│ └── media-typer@0.3.0
├── utils-merge@1.0.0
└── vary@1.0.1

npm WARN enoent ENOENT: no such file or directory, open '/Users/lucillekenney/Desktop/template/package.json’
npm WARN template No description
npm WARN template No repository field.
npm WARN template No README data
npm WARN template No license field.

Did you create a package.json file in your template folder by typing npm init (from that folder)?

No I didn’t. The ‘Comparing Front-End Frameworks’ tutorial doesn’t say to do that.

It’s step 1 create ‘template’ dir on Desktop and then cd into ‘template’ and do this ‘npm install express body-parser’ and that’s when I get the error …

I’m not sure if your question is a suggestion or a question? Did I miss something?

What does my not having a package.json file tell me? Does it tell me there is something wrong with my installation? Maybe I should find instructions on the web on how to uninstall everything and then reinstall it and see if I can get past these first two steps in this tutorial? Did I miss something in the tutorial that might explain my predicament?