Getting koa to work (nodejs web framework) - node.js

I am running Deepin and trying to get koa to work. There is little documentation on the subject.
I did the following as stated on koajs.com:
$ npm install -g n
$ n 0.11
$ node --harmony my-koa-app.js
I recieve the error:
➜test-koa-app$ sudo node --harmony test-koa-app.js
module.js:338
throw err;
^
Error: Cannot find module 'koa'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/karl/nodejs/test-koa-app/test-koa-app.js:1:73)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)

As Mike Kamermans mentioned in the question comments, to use a module in a node application, it must first be installed in the project directory.
To install it, run npm install koa in a terminal in your project folder.
If you've run npm init and setup a package.json file in your project, you can add the --save flag and save a record of the dependency with npm install --save koa.

Version 2 of koa now out. Go here:
https://github.com/koajs/koa

Related

Gulp error (module not found)

I have installed npm locally according to an article (I don't remember the URL). So that my npm packages are in ~/.npm-packages/. So gulp is in ~/.npm-packages/bin/gulp and this is a link: gulp -> ../lib/node_modules/gulp/bin/gulp.js
When I run which gulp I got /home/victor/.npm-packages/bin/gulp
When I go to the bin directory and run gulp like ./gulp.js -v I can see it works. However, when I run gulp globally I got such error:
module.js:338
throw err;
^
Error: Cannot find module '/usr/lib/node_modules/gulp/node_modules/v8flags/3.28.73.flags.json'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/usr/lib/node_modules/gulp/bin/gulp.js:25:22)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
So gulp is trying to find modules in /usr/lib, but why? Why not in my home directory? I have all these modules in ~/.npm-packages/lib/node_modules/gulp/node_modules
I'm absolutely confused and can't get gulp working. I've tried to reinstall it with the same effect.
This is what I did to solve the problem:
cd /usr/lib/node_modules/gulp/node_modules/v8flags
sudo node fetch.js
And that's it. The last instruction will create the required file.
This is what I did to solve the problem:
sudo npm install gulp && sudo npm install --save del && sudo gulp build

node.js returns "Cannot find module 'lockit-mongodb-adapter'"

I am going through my first node.js project. I've installed lockit , have a app.js file, and when I try to run it I get this error
module.js:340
throw err;
^ Error: Cannot find module 'lockit-mongodb-adapter'
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 new module.exports (C:\Users\xx\Documents\mailer\index.js:38:44)
at Object.<anonymous> (C:\Users\xx\Documents\mailer\examples\mongodb\app. js:32:14)
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)
I am quite certain I have lockit-mongodb-adapter installed.
You need to install the module. Cd to the root of your app directory and run this command and make sure lockit-mongodb-adapter is in your node modules directory.
npm install lockit-mongodb-adapter
Another thing you can do if you are certain it is installed is double check to see what is installed by running this command:
npm list
And this one to see what is installed globally:
npm list -g
Update:
I was able to reproduce the issue you where having. And to resolve it I deleted the module from the node moules directory. And re-installed with the following command:
npm install lockit-mongodb-adapter -save
It now shows up in npm list with no issues:

Node js Express module.js:340

I'm having trouble running my app in node. When I first got the module.js:340 error, I used a sudo npm install express -g, and it looked like Express is installed but when I run my app again I get this error.
module.js:340
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> (/Users/mac/Downloads/node-FED-master/app.js:6: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)
users-Mac-Pro:node-FED-master mac$
You've installed Express globally (with -g), which gives you access to the express command line tool, but Node programs can't access the global module. You need to install Express locally by doing npm install express in your project directory.
If the project has a package.json, a simple npm install in the project directory will install all necessary dependencies in it's correct versions.

Cannot find module 'node-gcm'

Im attempting to get Push notifications working with Android. Im following the tutorial here. It require installation of the node-gcm module of node.js. I installed this with the following command:
sudo npm install -g node-gcm
I have a file called notify.js. I run this with:
node notify.js
But I'm always getting the error:
module.js:333
throw err;
^
Error: Cannot find module 'node-gcm'
at Function.Module._resolveFilename (module.js:331:15)
at Function.Module._load (module.js:273:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object.<anonymous> (/var/www/PushPlay/notify.js:1:73)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Function.Module.runMain (module.js:490:10)
Any ideas?
If you've done a global install of the module, sometimes you need to create a symlink to the global module. Try npm link node-gcm.
Also try and install node-gcm without the global switch (npm install node-gcm), if it works locally you'll know it's an issue with the global install.

error running app after new install on Amazon EC2

For the first time trying to use Amazon EC2 to install node.js server. Doing according to this article. Installed node.js, then npm, then all the other modules. All without error. But for some reason, my server does not start. Can you please tell me where to find the error?
[ec2-user#domU-12-31-39-07-62-87 ~]$ node server.js
module.js:340
throw err;
^
Error: Cannot find module 'socket.io'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/ec2-user/server.js:3:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
[ec2-user#domU-12-31-39-07-62-87 ~]$ cd node
[ec2-user#domU-12-31-39-07-62-87 node]$ node server.js
module.js:340
throw err;
^
Error: Cannot find module '/home/ec2-user/node/server.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
It looks like it just couldn't find socket.io. Try this:
cd /home/ec2-user
npm install socket.io
node server.js
I agree with "The Reddest", however, the article says to install express which should install socket.io as a dependency. Did you run the last two npm commands in the article?
sudo npm install express -g
sudo npm install forever -g
Better yet, create a package.json file and install its dependencies local to the app rather than globally. Read more about that, here .. http://docs.nodejitsu.com/articles/getting-started/npm/what-is-the-file-package-json

Resources