[Startup Engineering] HW4: Cannot find module ‘express’

[email protected]:~/bitstarter$ node web.js

 throw err;
Error: Cannot find module 'express'
 at Function.Module._resolveFilename (module.js:338:15)
 at Function.Module._load (module.js:280:25)
 at Module.require (module.js:364:17)
 at require (module.js:380:17)
 at Object.<anonymous> (/home/ubuntu/bitstarter/web.js:19:15)
 at Module._compile (module.js:456:26)
 at Object.Module._extensions..js (module.js:474:10)
 at Module.load (module.js:356:32)
 at Function.Module._load (module.js:312:12)
 at Function.Module.runMain (module.js:497:10)

I can’t run node web.js, so try to find express library.

[email protected]:~/bitstarter$ ls
checks.json index.html package.json restler test.tar.gz
grader.js node_modules Procfile test web.js
[email protected]:~/bitstarter$ cd node_modules
[email protected]:~/bitstarter/node_modules$ ls
cheerio commander

[email protected]:~$ ls
bitstarter hello-world MKprime.js node_modules tmp
hello.js index.html MKprime.txt npm-debug.log
hello.js.save market-research.csv modules simple.sh
hello.js.save.1 market-research.js node.js something.txt
hello.txt market-research-wrapper.js node-js-sample somthing.txt
[email protected]:~$ cd node_modules
[email protected]:~/node_modules$ ls
accounting csv hello-world restler

I couldn’t find anywhere. so I try to install express.

[email protected]:~$ npm install -g express
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/express'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/express']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/express',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/express',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

It had errors. I refered to resolve here.


[email protected]:~$ sudo chown -R $USER /usr/local
[email protected]:~$ npm install -g express
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/connect/2.8.4
npm http GET https://registry.npmjs.org/commander/1.2.0
npm http GET https://registry.npmjs.org/mkdirp/0.3.5
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/fresh/0.1.0
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/send/0.1.3
npm http GET https://registry.npmjs.org/cookie-signature/1.0.1
npm http GET https://registry.npmjs.org/debug
npm http 200 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/mkdirp/0.3.5
npm http 200 https://registry.npmjs.org/commander/1.2.0
npm http 200 https://registry.npmjs.org/cookie/0.1.0
npm http 200 https://registry.npmjs.org/connect/2.8.4
npm http GET https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz
npm http GET https://registry.npmjs.org/commander/-/commander-1.2.0.tgz
npm http GET https://registry.npmjs.org/cookie/-/cookie-0.1.0.tgz
npm http GET https://registry.npmjs.org/connect/-/connect-2.8.4.tgz
npm http 200 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.1.tgz
npm http 200 https://registry.npmjs.org/fresh/0.1.0
npm http GET https://registry.npmjs.org/fresh/-/fresh-0.1.0.tgz
npm http 200 https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/methods/-/methods-0.0.1.tgz
npm http 200 https://registry.npmjs.org/cookie-signature/1.0.1
npm http 200 https://registry.npmjs.org/send/0.1.3
npm http GET https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.1.tgz
npm http GET https://registry.npmjs.org/send/-/send-0.1.3.tgz
npm http 200 https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/debug/-/debug-0.7.2.tgz
npm http 200 https://registry.npmjs.org/range-parser/-/range-parser-0.0.4.tgz
npm http 200 https://registry.npmjs.org/commander/-/commander-1.2.0.tgz
npm http 200 https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz
npm http 200 https://registry.npmjs.org/cookie/-/cookie-0.1.0.tgz
npm http 200 https://registry.npmjs.org/connect/-/connect-2.8.4.tgz
npm http 200 https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.1.tgz
npm http 200 https://registry.npmjs.org/fresh/-/fresh-0.1.0.tgz
npm http 200 https://registry.npmjs.org/methods/-/methods-0.0.1.tgz
npm http 200 https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.1.tgz
npm http 200 https://registry.npmjs.org/send/-/send-0.1.3.tgz
npm http 200 https://registry.npmjs.org/debug/-/debug-0.7.2.tgz
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/keypress
npm http GET https://registry.npmjs.org/qs/0.6.5
npm http GET https://registry.npmjs.org/formidable/1.0.14
npm http GET https://registry.npmjs.org/bytes/0.2.0
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http GET https://registry.npmjs.org/uid2/0.0.2
npm http 200 https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/mime/-/mime-1.2.9.tgz
npm http 200 https://registry.npmjs.org/keypress
npm http GET https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz
npm http 200 https://registry.npmjs.org/pause/0.0.1
npm http 200 https://registry.npmjs.org/uid2/0.0.2
npm http GET https://registry.npmjs.org/pause/-/pause-0.0.1.tgz
npm http GET https://registry.npmjs.org/uid2/-/uid2-0.0.2.tgz
npm http 200 https://registry.npmjs.org/qs/0.6.5
npm http 200 https://registry.npmjs.org/bytes/0.2.0
npm http GET https://registry.npmjs.org/qs/-/qs-0.6.5.tgz
npm http 200 https://registry.npmjs.org/formidable/1.0.14
npm http GET https://registry.npmjs.org/bytes/-/bytes-0.2.0.tgz
npm http GET https://registry.npmjs.org/formidable/-/formidable-1.0.14.tgz
npm http 200 https://registry.npmjs.org/mime/-/mime-1.2.9.tgz
npm http 200 https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz
npm http 200 https://registry.npmjs.org/uid2/-/uid2-0.0.2.tgz
npm http 200 https://registry.npmjs.org/pause/-/pause-0.0.1.tgz
npm http 200 https://registry.npmjs.org/bytes/-/bytes-0.2.0.tgz
npm http 200 https://registry.npmjs.org/formidable/-/formidable-1.0.14.tgz
npm http 200 https://registry.npmjs.org/qs/-/qs-0.6.5.tgz
/usr/local/bin/express -> /usr/local/lib/node_modules/express/bin/express
[email protected] /usr/local/lib/node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
[email protected]:~$

But this error is continuing when command node web.js.

I try to install setup.sh again. It maybe install package.json. BUT!!!!!!!! :(

I try again

 $ npm install express 

after successfully installing, it working! why didn’t work before?

[email protected]:~/bitstarter$ npm install express
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/express/-/express-2.5.11.tgz
npm http 200 https://registry.npmjs.org/express/-/express-2.5.11.tgz
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/mime/1.2.4
npm http GET https://registry.npmjs.org/mkdirp/0.3.0
npm http GET https://registry.npmjs.org/qs
npm http 200 https://registry.npmjs.org/mime/1.2.4
npm http 200 https://registry.npmjs.org/mkdirp/0.3.0
npm http GET https://registry.npmjs.org/mime/-/mime-1.2.4.tgz
npm http GET https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz
npm http 200 https://registry.npmjs.org/qs
npm http GET https://registry.npmjs.org/qs/-/qs-0.4.2.tgz
npm http 200 https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz
npm http 200 https://registry.npmjs.org/mime/-/mime-1.2.4.tgz
npm http 200 https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/connect/-/connect-1.9.2.tgz
npm http 200 https://registry.npmjs.org/qs/-/qs-0.4.2.tgz
npm http 200 https://registry.npmjs.org/connect/-/connect-1.9.2.tgz
npm http GET https://registry.npmjs.org/formidable
npm http 200 https://registry.npmjs.org/formidable
[email protected] node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected] ([email protected])
[email protected]:~/bitstarter$ node web.js
Listening on 5000
^[[B^Cubu[email protected]:~/bitstarter$ node web.js
Listening on 8080

I don’t know well… refer to this issue 


스크린샷 2013-07-14 오후 10.17.14

앱 & 서비스 기획자입니다. 잘하고 싶어요.

  • Pingback: [Startup Engineering] HW6-1. (ing) | Minieetea()

  • No need, don’t worry! I just tried to explain why your previous attempts hadn’t worked!
    As of now, just use npm install (i.e. npm install express) to install new packages or sudo (i.e. sudo npm install -g express) to install globally (if you everneed to), and it will work in 100% of the cases =)

    • thanks your advice. I will remember it :)

  • tricky one!

    first time you tried to install express with global option (-g). This requires superuser access, so you could of done: sudo npm install -g express. Instead, you changed the owner of /use/lib folder. Now you were able to install express but due to the change, node itself wasn’t able to access the files you installed!
    the next attempt (local install, without the -g option) should work fine though it only installs the package for the current application (which was fine for the assignment)

    so, whenever you need to install a package, just install it with npm install . If you really need it to be global, use sudo npm install -g


    • oops :( node can’t access the files ? then, how can I do? needs uninstall and re-intall?

Sliding Sidebar