{"action":"created","issue":{"url":"https://api.github.com/repos/Unitech/PM2/issues/1146","labels_url":"https://api.github.com/repos/Unitech/PM2/issues/1146/labels{/name}","comments_url":"https://api.github.com/repos/Unitech/PM2/issues/1146/comments","events_url":"https://api.github.com/repos/Unitech/PM2/issues/1146/events","html_url":"https://github.com/Unitech/PM2/issues/1146","id":66563455,"number":1146,"title":"Incorrect module loading in cluster mode with NODE_PATH","user":{"login":"Jokero","id":434135,"avatar_url":"https://avatars.githubusercontent.com/u/434135?v=3","gravatar_id":"","url":"https://api.github.com/users/Jokero","html_url":"https://github.com/Jokero","followers_url":"https://api.github.com/users/Jokero/followers","following_url":"https://api.github.com/users/Jokero/following{/other_user}","gists_url":"https://api.github.com/users/Jokero/gists{/gist_id}","starred_url":"https://api.github.com/users/Jokero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jokero/subscriptions","organizations_url":"https://api.github.com/users/Jokero/orgs","repos_url":"https://api.github.com/users/Jokero/repos","events_url":"https://api.github.com/users/Jokero/events{/privacy}","received_events_url":"https://api.github.com/users/Jokero/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"jshkurti","id":7647602,"avatar_url":"https://avatars.githubusercontent.com/u/7647602?v=3","gravatar_id":"","url":"https://api.github.com/users/jshkurti","html_url":"https://github.com/jshkurti","followers_url":"https://api.github.com/users/jshkurti/followers","following_url":"https://api.github.com/users/jshkurti/following{/other_user}","gists_url":"https://api.github.com/users/jshkurti/gists{/gist_id}","starred_url":"https://api.github.com/users/jshkurti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jshkurti/subscriptions","organizations_url":"https://api.github.com/users/jshkurti/orgs","repos_url":"https://api.github.com/users/jshkurti/repos","events_url":"https://api.github.com/users/jshkurti/events{/privacy}","received_events_url":"https://api.github.com/users/jshkurti/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2015-04-06T09:02:49Z","updated_at":"2015-04-08T13:31:34Z","closed_at":null,"body":"OS - Ubuntu 14.04.1 LTS\r\nNode.js - 0.12.0\r\npm2 - 0.12.9\r\n\r\nFor example, I have two apps \"pm2\" and \"main\" with similar structure:\r\n```\r\napp.js\r\napps.json\r\nlib/logger.js\r\n```\r\n\r\napp.js:\r\n```javascript\r\nconsole.log('NODE_PATH=' + process.env.NODE_PATH);\r\n\r\nrequire('lib/logger')();\r\n\r\nvar http = require('http');\r\nhttp.createServer().listen(8080); // 8081 for \"main\" app\r\n```\r\n\r\napps.json:\r\n```javascript\r\n{\r\n  \"apps\" : [{\r\n    \"name\":      \"pm2\", // \"main\"\r\n    \"script\":    \"app.js\",\r\n    \"exec_mode\": \"cluster_mode\",\r\n    \"instances\": 0\r\n  }]\r\n}\r\n```\r\n\r\nlib/logger.js:\r\n```javascript\r\nmodule.exports = function() {\r\n   console.log('logger from pm2 app'); // console.log('logger from main app');\r\n};\r\n```\r\n    \r\n1) Run \"pm2\" app:\r\n```\r\ndmitry@dmitry:~/dev/pm2$ NODE_PATH=/home/dmitry/dev/pm2 pm2 startOrRestart apps.json\r\n```\r\n\r\nLogs:\r\n```\r\npm2-0 (out): NODE_PATH=/home/dmitry/dev/pm2\r\npm2-0 (out): logger from pm2 app\r\npm2-1 (out): NODE_PATH=/home/dmitry/dev/pm2\r\npm2-1 (out): logger from pm2 app\r\npm2-2 (out): NODE_PATH=/home/dmitry/dev/pm2\r\npm2-2 (out): logger from pm2 app\r\npm2-3 (out): NODE_PATH=/home/dmitry/dev/pm2\r\npm2-3 (out): logger from pm2 app\r\n```\r\n\r\nEverything is good: logger was loaded from \"pm2\" directory. \r\n\r\n2) Run \"main\" app\r\n```\r\ndmitry@dmitry:~/dev/main$ NODE_PATH=/home/dmitry/dev/main pm2 startOrRestart apps.json\r\n```\r\nLogs:\r\n```\r\npm2-0 (out): NODE_PATH=/home/dmitry/dev/pm2\r\npm2-0 (out): logger from pm2 app\r\npm2-1 (out): NODE_PATH=/home/dmitry/dev/pm2\r\npm2-1 (out): logger from pm2 app\r\npm2-2 (out): NODE_PATH=/home/dmitry/dev/pm2\r\npm2-2 (out): logger from pm2 app\r\npm2-3 (out): NODE_PATH=/home/dmitry/dev/pm2\r\npm2-3 (out): logger from pm2 app\r\nmain-4 (out): NODE_PATH=/home/dmitry/dev/main\r\nmain-4 (out): logger from pm2 app\r\nmain-5 (out): NODE_PATH=/home/dmitry/dev/main\r\nmain-5 (out): logger from pm2 app\r\nmain-6 (out): NODE_PATH=/home/dmitry/dev/main\r\nmain-6 (out): logger from pm2 app\r\nmain-7 (out): NODE_PATH=/home/dmitry/dev/main\r\nmain-7 (out): logger from pm2 app\r\n```\r\n\r\nNODE_PATH is correct, but logger was loaded from \"pm2\" directory. So previous value of NODE_PATH was used, not current"},"comment":{"url":"https://api.github.com/repos/Unitech/PM2/issues/comments/90917144","html_url":"https://github.com/Unitech/PM2/issues/1146#issuecomment-90917144","issue_url":"https://api.github.com/repos/Unitech/PM2/issues/1146","id":90917144,"user":{"login":"chylvina","id":886818,"avatar_url":"https://avatars.githubusercontent.com/u/886818?v=3","gravatar_id":"","url":"https://api.github.com/users/chylvina","html_url":"https://github.com/chylvina","followers_url":"https://api.github.com/users/chylvina/followers","following_url":"https://api.github.com/users/chylvina/following{/other_user}","gists_url":"https://api.github.com/users/chylvina/gists{/gist_id}","starred_url":"https://api.github.com/users/chylvina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chylvina/subscriptions","organizations_url":"https://api.github.com/users/chylvina/orgs","repos_url":"https://api.github.com/users/chylvina/repos","events_url":"https://api.github.com/users/chylvina/events{/privacy}","received_events_url":"https://api.github.com/users/chylvina/received_events","type":"User","site_admin":false},"created_at":"2015-04-08T13:31:34Z","updated_at":"2015-04-08T13:31:34Z","body":"+1 "}}