I'm using Heroku and I get this error..

2016-10-10T03:34:11.188366+00:00 app[web.1]: Error: Cannot find module 'module1.js'
2016-10-10T03:34:11.188369+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:339:15)
2016-10-10T03:34:11.188370+00:00 app[web.1]:     at Function.Module._load (module.js:290:25)
2016-10-10T03:34:11.188371+00:00 app[web.1]:     at Module.require (module.js:367:17)
2016-10-10T03:34:11.188371+00:00 app[web.1]:     at require (internal/module.js:20:19)
2016-10-10T03:34:11.188372+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:42:15)
2016-10-10T03:34:11.188373+00:00 app[web.1]:     at Module._compile (module.js:413:34)
2016-10-10T03:34:11.188374+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:422:10)
2016-10-10T03:34:11.188374+00:00 app[web.1]:     at Module.load (module.js:357:32)
2016-10-10T03:34:11.188375+00:00 app[web.1]:     at Function.Module._load (module.js:314:12)
2016-10-10T03:34:11.188375+00:00 app[web.1]:     at Function.Module.runMain (module.js:447:10)

app.js

/**CUSTOM_MODULES**/

var module1 = require('module1.js');

/**MODULES_END**/

module1.js

function module1(){
    //My code
}

module.exports = module1;

module1.js is in the same directory as my app.js.

I have tried countless things but nothing seems to work.

I have tried:

 var module1 = require('module1.js');
 var module1 = require('./module1.js');
 var module1 = require('../module1.js');
 var module1 = require('module1');

package.json : app.js

{
  "name": "nano-server",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "dependencies": {
    "express": "^4.14.0",
    "mysql": "^2.11.1",
    "socket.io": "^1.4.8",  
    "module1": "0.0.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC"
}

package.json : module1

 {
  "name": "module1",
  "version": "0.0.0",
  "description": "get something",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": {
    "name": "sergey"
  },
  "license": "BSD-2-Clause",
  "readme": "ERROR: No README data found!",
  "_id": "[email protected]",
  "dist": {
    "shasum": "dc9b96f8a43b596bf735da4d2004ba410429bde0",
    "tarball": "https://registry.npmjs.org/module1/-/module1-0.0.0.tgz"
  },
  "_from": "module1@latest",
  "_npmVersion": "1.3.11",
  "_npmUser": {
    "name": "sergey-user",
    "email": "[email protected]"
  },
  "maintainers": [
    {
      "name": "sergey-user",
      "email": "[email protected]"
    }
  ],
  "directories": {},
  "_shasum": "dc9b96f8a43b596bf735da4d2004ba410429bde0",
  "_resolved": "https://registry.npmjs.org/module1/-/module1-0.0.0.tgz"
}

directory

_server
    .git
    node_modules
        .bin
        express
        module1
            index.js
            package.json
        mysql
        node-mysql
        node-uuid
        socket.io
    package.json
    server.js
share|improve this question

Try var module1 = require('./module1');

share|improve this answer
    
Didn't work. module1.js is not in any extra folders, same directory as app.js – tery.blargh Oct 10 '16 at 3:46
1  
There is a nice tutorial on this if it helps. sitepoint.com/understanding-module-exports-exports-node-js Follow the steps. – Fida Oct 10 '16 at 3:47
    
Thanks, but I don't think there is anything wrong with the code, rather a method I haven't done or so – tery.blargh Oct 10 '16 at 3:54

Adding your module as a dependency to your application would resolve this issue. To achieve that try the below command.

npm install module1 --save

Hope this helps!

share|improve this answer
    
I did this, changed name to index.js and put in module1 folder, it finally recognized the module1 folder (thank you), but it seems to not initiate index.js because now it's calling an error on "module1 is not a function" in my app.js – tery.blargh Oct 10 '16 at 4:00
1  
Can you please post your index.js code? – David R Oct 10 '16 at 4:02
    
It is the module.js I have posted. I also switched the module1 package.json from "main": "github.js" to "main": "index.js" – tery.blargh Oct 10 '16 at 4:04
1  
Can you post your directory structure if possible? – David R Oct 10 '16 at 4:10
1  
No. I meant the directory/file hierarchy – David R Oct 10 '16 at 4:15

install npm -g and try again afterwords.

share|improve this answer
    
Tried npm install -g and keep trying different require() directory, so far still not working – tery.blargh Oct 10 '16 at 3:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.