PM2 Start Appname Returning Error Cannot Find Modules in Ubuntu 18.04 LTS

Viewed 1445

This is my first nodejs app and when I try to run the app using PM2 then app start and immediately it's become to errored and pm2 logs showing this

/root/.pm2/logs/app-out.log last 15 lines:
/root/.pm2/logs/app-error.log last 15 lines:
1|app      |     at Module.load (module.js:565:32)
1|app      |     at tryModuleLoad (module.js:505:12)
1|app      |     at Function.Module._load (module.js:497:3)
1|app      |     at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerForkLegacy.js:28:21) code: 'MODULE_NOT_FOUND' }
1|app      | { Error: Cannot find module 'express'
1|app      |     at Function.Module._resolveFilename (module.js:547:15)
1|app      |     at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
1|app      |     at require (internal/module.js:11:18)
1|app      |     at Object.<anonymous> (/var/www/whatsclone/app.js:18:17)
1|app      |     at Module._compile (module.js:652:30)
1|app      |     at Object.Module._extensions..js (module.js:663:10)
1|app      |     at Module.load (module.js:565:32)
1|app      |     at tryModuleLoad (module.js:505:12)
1|app      |     at Function.Module._load (module.js:497:3)
1|app      |     at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerForkLegacy.js:28:21) code: 'MODULE_NOT_FOUND' }

I have tried sudo pm2 update | npm install | npm install express

1|app            | { Error: Cannot find module 'lodash'
1|app            |     at Function.Module._resolveFilename (module.js:547:15)
1|app            |     at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
1|app            |     at require (internal/module.js:11:18)
1|app            |     at Object.<anonymous> (/var/www/whatsclone/config/environment/index.js:11:11)
1|app            |     at Module._compile (module.js:652:30)
1|app            |     at Object.Module._extensions..js (module.js:663:10)
1|app            |     at Module.load (module.js:565:32)
1|app            |     at tryModuleLoad (module.js:505:12)
1|app            |     at Function.Module._load (module.js:497:3)
1|app            |     at Module.require (module.js:596:17) code: 'MODULE_NOT_FOUND' }
PM2              | App [app:1] exited with code [1] via signal [SIGINT]
PM2              | App [app:1] starting in -fork mode-
PM2              | App [app:1] online

Now the output looks like this after run npm install express

packagee.json is here

{
  "name": "whatsclone",
  "version": "1.0.0",
  "description": "restfull whatscloneAPI",
  "private": true,
  "scripts": {
    "start": "node ./bin/www",
    "test": "grunt test"
  },
  "main": "./bin/www",
  "keywords": [
    "whatsclone",
    "api",
    "chat",
    "call"
  ],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "grunt": "^1.0.4",
    "grunt-apidoc": "^0.11.0",
    "grunt-contrib-watch": "^1.1.0",
    "grunt-mocha-test": "^0.13.3",
    "grunt-nodemon": "^0.4.2",
    "mocha": "^6.2.2",
    "nodemon": "^2.0.1"
  },
  "dependencies": {
    "async": "^3.1.0",
    "basic-auth": "^2.0.1",
    "body-parser": "^1.19.0",
    "composable-middleware": "^0.3.0",
    "connect-mongo": "^3.2.0",
    "cookie-parser": "^1.4.4",
    "dotenv": "^8.2.0",
    "ejs": "^2.6.2",
    "express": "^4.17.1",
    "express-jwt": "^5.3.1",
    "express-session": "^1.17.0",
    "express-validator": "^5.3.1",
    "i18n": "^0.8.4",
    "jsonwebtoken": "^8.5.1",
    "lusca": "^1.6.1",
    "mongodb": "^3.3.5",
    "mongoose": "^5.7.13",
    "morgan": "^1.9.1",
    "mosca": "^2.8.3",
    "mqtt": "^3.0.0",
    "multer": "^1.4.2",
    "readdir": "0.1.0",
    "serve-favicon": "^2.5.0",
    "twilio": "^3.37.1",
    "underscore": "^1.9.1",
    "uuid": "^3.3.3"
  }
}

Nothing fixed for me. Tried many tutorials from the internet and from this forum. still, the problem exists please I'm asking some help to fix this

node -v v8.10.0

npm -v 3.5.2

0 Answers
Related