1

Ok I've read tens of similar questions but none have been able to fix my problem - mainly because I think my problem is a bit deeper.

I have several modules working fine on my server (Nodejitsu) which I think I installed the same way which was: npm install express/connect/mongojs etc...

In my server.js :

var express = require('express');
var team = require('./team');
var users = require('./users');
var scheduler = require('node-schedule');

Now I'm trying to get node-schedule module to work so I installed via npm while in the directory of my server.js file the module indeed enters node_modules folder but when I deploy my app I get this:

error:   module.js:340
error:       throw err;
error:             ^
error:   Error: Cannot find module 'node-schedule'
error:       at Function.Module._resolveFilename (module.js:338:15)
error:       at Function.Module._load (module.js:280:25)
error:       at Module.require (module.js:364:17)
error:       at require (module.js:380:17)
error:       at Object.<anonymous> (/opt/run/snapshot/package/server.js:5:1)
error:       at Module._compile (module.js:456:26)
error:       at Object.Module._extensions..js (module.js:474:10)
error:       at Module.load (module.js:356:32)
error:       at Function.Module._load (module.js:312:12)
error:       at Function.Module.runMain (module.js:497:10)

I think my problem could have something to do with my package.json file which is pretty much empty:

 {
      "name": "wePlay",
      "subdomain": "wePlay",
      "scripts": {
        "start": "node server.js"
      },
      "version": "0.0.0-203",
      "engines": {
        "node": "0.10.x"
      }
}

Now I have in my node_modules folder several modules as I mentioned (express,mongojs..) and they all work fine when I deploy, even though they are not mentioned in my package.json file - but now this new module, nothing... I've tried (based on past threads) to install it with -g and still nothing, I've also tried linking it, nothing...

I see there is a problem because when I try to deploy my app I see this as the app is deploying:

connect@2.7.3 node_modules/connect
├── fresh@0.1.0
├── pause@0.0.1
├── cookie-signature@0.0.1
├── bytes@0.2.0
├── buffer-crc32@0.1.1
├── cookie@0.0.5
├── debug@0.7.2
├── send@0.1.0 (range-parser@0.0.4, mime@1.2.6)
├── formidable@1.0.11
└── qs@0.5.1

express@3.2.2 node_modules/express
├── methods@0.0.1
├── fresh@0.1.0
├── range-parser@0.0.4
├── cookie-signature@1.0.1
├── qs@0.6.3
├── buffer-crc32@0.2.1
├── cookie@0.0.5
├── debug@0.7.2
├── commander@0.6.1
├── mkdirp@0.3.4
├── send@0.1.0 (mime@1.2.6)
└── connect@2.7.8 (pause@0.0.1, bytes@0.2.0, formidable@1.0.13)

nodemailer@0.4.4 node_modules/nodemailer
├── simplesmtp@0.3.1 (xoauth2@0.1.8, rai@0.1.7)
└── mailcomposer@0.1.33 (mime@1.2.9, mimelib@0.2.12)

mongojs@0.7.5 node_modules/mongojs
├── thunky@0.1.0
├── readable-stream@1.0.2
└── mongodb@1.3.6 (kerberos@0.0.2, bson@0.1.8)

so obviously node-schedule is not there. I just can't seem to understand a) How I got the original modules to work, when my server.js package.json is empty... b) how can require not find it when its sitting right there, next to express connect and mongojs...

orepor
  • 905
  • 2
  • 13
  • 23
  • 3
    Node might not be able to read the directory of the module due to permissions/ownership. In your development environment it is common to do `npm install [module] --save` which will add the dependency to your package.json (or you can add it manually). After this, an `npm install` should install all your dependencies. – Kevin Reilly Mar 12 '14 at 19:50
  • Thanks for the answer - still can't find the module. and doing npm install --save didn't actually add anything to my package.json. I added dependencies manually in to package.json, still nothing `.... "main": "server.js", "dependencies": { "mongojs": "0.7.5", "express": "3.2.2", "node-schedule": "0.1.13" }` – orepor Mar 12 '14 at 20:40
  • 1
    Any other suggestions? I'm so lost here.. – orepor Mar 13 '14 at 12:45

1 Answers1

2

This worked for me in localhost:

after doing: npm install node-schedule --save

You have the file schedule.js under node_modules.

var scheduler = require('./node_modules/node-schedule/lib/schedule.js');