graham-walker / youtube-dl-react-viewer

Web app for youtube-dl/yt-dlp, created using the MERN stack
https://react.gwalkerux.com/
MIT License
92 stars 9 forks source link

New Install - issue with PM2 and dotenv/config #13

Closed dyslexicjedi closed 3 years ago

dyslexicjedi commented 3 years ago

I decided to take this off docker and put it on it's own server. I migrated the mongodb to the new server and followed the instructions on the README for install.

When I try to start the app, I get this:

`rob@SRV01:~/youtubereact/youtube-dl-react-viewer release 1.2.1$ sudo pm2 start ./youtube-dl-express-backend/pm2.config.json -l log.log -o out.log -e error.log

In-memory PM2 is out-of-date, do: $ pm2 update In memory PM2 version: 4.5.0 Local PM2 version: 4.5.1

[PM2] Applying action restartProcessId on app [youtube-dl-react-viewer](ids: [ 0 ]) [PM2] youtube-dl-react-viewer ✓ ┌─────┬────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐ │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ ├─────┼────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤ │ 0 │ youtube-dl-react-viewer │ default │ N/A │ fork │ 119885 │ 0s │ 140… │ online │ 0% │ 19.5mb │ root │ disabled │ └─────┴────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘ rob@kub01:~/youtubereact/youtube-dl-react-viewer release 1.2.1$ sudo pm2 list

In-memory PM2 is out-of-date, do: $ pm2 update In memory PM2 version: 4.5.0 Local PM2 version: 4.5.1

┌─────┬────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐ │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ ├─────┼────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤ │ 0 │ youtube-dl-react-viewer │ default │ N/A │ fork │ 0 │ 0 │ 140… │ errored │ 0% │ 0b │ root │ disabled │ └─────┴────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘`

I look at the log files using "sudo pm2 logs youtube-dl-react-viewer

|youtube- | Error: Cannot find module 'dotenv/config' 0|youtube- | Require stack: 0|youtube- | - internal/preload 0|youtube- | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15) 0|youtube- | at Function.Module._load (internal/modules/cjs/loader.js:725:27) 0|youtube- | at Module.require (internal/modules/cjs/loader.js:952:19) 0|youtube- | at Module._preloadModules (internal/modules/cjs/loader.js:1217:12) 0|youtube- | at loadPreloadModules (internal/bootstrap/pre_execution.js:449:5) 0|youtube- | at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:76:3) 0|youtube- | at internal/main/run_main_module.js:7:1 { 0|youtube- | code: 'MODULE_NOT_FOUND', 0|youtube- | requireStack: [ 'internal/preload' ] 0|youtube- | }

But yet, if I run the basic node command from the youtube-dl-express-backend folder: node --require dotenv/config index.js The application works fine, no errors, page displays, can watch videos etc.

Any thoughts on why I can't use PM2 to start the app?

JamoDevNich commented 3 years ago

I think node is looking for dotenv/config and can't find it, because pm2 is setting the cwd to the folder it's started in. The only thing I can think of is maybe the dev's machine has dotenv/config installed to the global npm modules?

You could try starting pm2 while inside the backend folder (instead of the project root) and see if that works.

Alternatively PM2 has a cwd config option that could be used here

{
    "apps": [{
        "name": "youtube-dl-react-viewer",
        "script": "index.js",
        "node_args": "--require dotenv/config",
        "cwd": "youtube-dl-express-backend"
    }]
}