MERN deployment to Heroku - node.js

I'm having a really hard time figuring out how to deploy my app to heroku. Im new to all of this so I've tried different ways and following different tutorials but I just can't seem to find out how to do it.
This is my github repo:
https://github.com/solecity/card-deck-manager-app/tree/main
And in my logs from heroku I'm getting different errors:
2021-07-14T12:22:33.592361+00:00 app[web.1]: npm ERR! missing script: start
Starting process with command `node index.js`
2021-07-14T12:25:08.838023+00:00 app[web.1]: internal/modules/cjs/loader.js:905
2021-07-14T12:25:08.838048+00:00 app[web.1]: throw err;
2021-07-14T12:25:08.838048+00:00 app[web.1]: ^
2021-07-14T12:25:08.838049+00:00 app[web.1]:
2021-07-14T12:25:08.838049+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2021-07-14T12:27:16.812794+00:00 app[web.1]: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'express' imported from /app/server/index.js
If anyone could shed some light on how I can fix this it will be greatly appreciated

as the error states, you need to provide a start script in your package.json
apparently this is what heroku tries to runs. (error 1)
And if it doesn't find it, it runs something like node index.js (error 2)
also, you have not registered express in your dependencies in the main package.json so heroku doesn't install it. (error 3)
I'm not very used to heroku, but i think you should create 2 separate projects, and register them separately in heroku. that way he would find onlythe appropriate package.json and run.

Related

Puppeteer and nodejs throws error with Heroku

I created an app and ran it on my localhost which worked perfectly fine.
Then tried to deploy on Heroku, added Puppeteer Heroku and nodejs build pack.
Added the following args to the puppeteer launch function:
const browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox"],
});
also deployed with:
$ git add .
$ git commit -m "First commit"
$ git push heroku main
So far so good, no problems during deployment.
But when I open up the application, I just see that:
and get following errors in the logs:
2022-10-17T18:44:50.357107+00:00 heroku[web.1]: Starting process with command `npm start`
2022-10-17T18:44:52.117360+00:00 app[web.1]:
2022-10-17T18:44:52.117423+00:00 app[web.1]: > fetch-data#1.0.0 start
2022-10-17T18:44:52.117426+00:00 app[web.1]: > node server.js
2022-10-17T18:44:52.117429+00:00 app[web.1]:
2022-10-17T18:44:52.439078+00:00 app[web.1]: Listening on port 41022...
2022-10-17T18:44:52.441949+00:00 app[web.1]: /app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:69
2022-10-17T18:44:52.441949+00:00 app[web.1]: throw new Error(missingText);
2022-10-17T18:44:52.441949+00:00 app[web.1]: ^
2022-10-17T18:44:52.441950+00:00 app[web.1]:
2022-10-17T18:44:52.441951+00:00 app[web.1]: Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (1045629).
2022-10-17T18:44:52.441951+00:00 app[web.1]: at ChromeLauncher.launch (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:69:23)
2022-10-17T18:44:52.441951+00:00 app[web.1]: at async start (/app/bot.js:13:19)
As I can see he is trying to get to "/app/node_modules/puppeteer-core/.." which would be the wrong I assume?
Anyone who can help me out or prefer something else?
Thanks in advance!

Nodemon app cannot find module when restarting

I'm currently building a RESTful API. I start my MongoDB server using the command mongod. When I restart my Node server (using rs), however, it throws the following error:
[nodemon] starting `node todoListApi`
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'C:\Users\Zakaria5\Desktop\Stage Technique
2019\zen-networks-backend\todoListApi'
at Function.Module._resolveFilename
(internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
[nodemon] app crashed - waiting for file changes before starting...
I Googled this error, and the solution seemed to be to remove the node_modules directory. However, when I type rm -rf nodes_modules, it displays that the command is not found. I also tried using npm install and npm start, but this throws an error, as well. What am I doing wrong?
I resolve the problem by fixing the path !! Well , when i type npm install and npm start ! It displays an error which confirms that the file isnt available in a path by default !! (in my case) C/users/Zakaria/package.json !! when i look for that file i didnt find it ! Thus , I have to change the path which contains my package.json file . I used that command " npm start --prefix TheRealPath " Hence , the RESTful API starts on port : 3000 !! :P

Log file (not found) / Heroku

While debugging an app on Heroku, I get this kind of message in the log console:
............
app[web.1]:
app[web.1]: npm ERR! A complete log of this run can be found in:
app[web.1]: npm ERR! /app/.npm/_logs/2017-08-19T03_00_34_428Z-debug.log
heroku[web.1]: Process exited with status 1
My problem is that I don't know how to find this file:
/app/.npm/_logs/2017-08-19T03_00_34_428Z-debug.log
The given path taken as is, is obviously wrong and wherever I look I do not see it.
Anyone knows where the file is?
I have the same question. Not able to find this log file.
However, you can view the log by setting it to verbose
heroku config:set NPM_CONFIG_LOGLEVEL=verbose
and then running git push heroku master

Heroku Deploy Error: Cannot find module '/app/index.js'

I' m trying to deploy mt app on Heroku but I always get the same error:
2016-08-18T10:16:10.988982+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-08-18T10:16:13.180369+00:00 app[web.1]: module.js:341
2016-08-18T10:16:13.180389+00:00 app[web.1]: throw err;
2016-08-18T10:16:13.180390+00:00 app[web.1]: ^
2016-08-18T10:16:13.180391+00:00 app[web.1]:
2016-08-18T10:16:13.180392+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2016-08-18T10:16:13.180393+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:339:15)
2016-08-18T10:16:13.180394+00:00 app[web.1]: at Function.Module._load (module.js:290:25)
2016-08-18T10:16:13.180394+00:00 app[web.1]: at Function.Module.runMain (module.js:447:10)
2016-08-18T10:16:13.180399+00:00 app[web.1]: at node.js:405:3
2016-08-18T10:16:13.271966+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T10:16:13.273383+00:00 heroku[web.1]: State changed from starting to crashed
As I read in similar requests I have already added a Procfile containing the following code: web: node index.js, but I still have same issue.
Anybody have any idea where the problem is? Any guidance would be greatly appreciated.
Thank you in advance!
Is your index.js file in your root directory?
web: node ./index.js
Your file might be nested like so app/src/index.js
web: node ./src/index.js
Does your index.js have an uppercase 'I'? It has to be index.js and not Index.js
If you do have your index.js file at the root of your project, but heroku's error says that the module cannot be found. Then, the problem you are having might be due to GIT.
How can we make sure this is the case?
Well, your git repo might not be adding your index.js file to commits nor pushing it to heroku. You can verify this by looking at the files that git is watching in your local repo with the following command:
git ls-files
Your index.js file should be listed. If not, then your file is being ignored.
Solution: Force add your file.
git add --force ./index.js
Now you can commit and push to heroku and you should be up and running.
This might also be the case when having your index file inside a dist directory or src (app/dist/index.js or app/src/index.js).
Add relative path for index.js file as bellow
web: node ./index.js
I am getting this error also. then I solve it by fixing importing file. My folder was was in lowercase like the product, and I import it like Product. It doesn't give me errors in localhost. Please check if the import files path is right in the index file.
My issue was a fault with my local development environment. Somehow...JavaScript code was being injected into my app project, which I didn't do.
Not knowing this was occurring, Heroku started seeing errors during my push, like "can't find jQuery, even though your using it in your app". I was like "what????, I'm not even using jQuery." I then re-opened a .js file in my project...and there it was, a const variable declaring jquery. So I say all that say, check your VSCode extensions, your third party npm packages, and everything for that matter to make sure things like this are not happening to you.
If error still happening, try using this:
web: node .
Go to your package.json file in root directory of any sub directory with another instance.
Change the script tag from "start": "node start" to "start": "node app.js".
Please note: in my case my main file is app.js yours can be index.js or server.js or anything you named it.
it can also happen if you give space in folders name or create your files in multiple folders then it will work in localhost but in server it will give you application error so don't make multiple folders and as well as don't give space in them and specify path correctly then it will work fine.

Error running grunt/starting server.js

For some quick background, I am following a MEANio tutorial found here. Now, I am at the part where I have run mean init, it has finished, and then cd into the project directory and run
npm install
After fixing a brief JSON syntax issue inside package.json (the end of the file was slightly mis-typed), I attempted to run
grunt
Hook task, clean, jshint, and csslint all ran fine, and then when I get to the portion of the build script that runs
node --debug server.js
I run into errors
events.js:72
throw er; // Unhandled 'error' event
Error: listen EADDRNOTAVAIL
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1024:19)
at listen (net.js:1065:10)
at net.js:1147:9
at asyncCallback (dns.js:68:16)
at Object.onanswer [as oncomplete] (dns.js:121:9)
[nodemon] app crashed - waiting for file changes before starting...
I am pretty clueless about the inner workings of Node, does anyone know what this error refers to? I followed the MEANio tutorial nearly exactly, with the exception of where my node is at, I just have it in a folder that I have added to my $PATH in my .bashrc file. Could someone give me some advice on what files to check/debug?
The EADDRNOTAVAIL error typically occurs when you are trying to run a server on a port that is already in use. That tutorial suggests that the port would be 3000 (which is a typical default for Node applications). You should check to see that you do not have anything else running on port 3000 already.

Resources