deploying Node on heroku error after build successful - node.js

i have been trying to deploy a node.js app on heroku. the app run successfully on local machine and it build successful with git heroku push master. but when try to open the app on heroku, it shows a blank page and on the console i got the bellow error.
so i my app i uses owlcarousel, and react -carousel. thanks

Try running it locally with NODE_ENV=production node index.js to see if you can reproduce the error like that. Check the .gitignore to see if you are not leaving out some important files. Check the package.json If a module that is included in the package.json is missing from the build or the production app, it may have been removed by Heroku during pruning. And also, in order to create a smaller slug size for apps, the buildpack will prune out the devDependencies from the package.json at the end of the build, so that the slug will only include the dependencies that are listed at runtime. If there is a dependency that is in the devDependencies that is needed after the prune occurs, move the dependency to dependencies, so it is not removed. Look here for more info, troubleshooting Node.js deployment on Heroku.

Related

Heroku applications and building process

I have just one question:
Why when you push to heroku, it do same all tasks to execute app?
For example I just modified one file index.js, ok, I need to git add index.js, git commit -am "Message" and heroku push origin master, but when I'm pushing to heroku, it pushing one file but do a lot of unnecessary things like
Again installing Node
Again installing dependencies (node modules), there are the same but heroku again download all dependencies
Again build cache of node modules
Why Heroku can't analyze package.json and do not install again new modules? Why it installs again Node if in Procfile I have the same web: npm run server? These actions are eating a lot of time and resources, I'm don't understand that.
you can create a ci/cd pipeline and deploy directly from your github page

How to install and deploy node.js application?

I'm new to node.js. After creating modularized project with express, tests, .nvmrc etc. it's finally time to deploy the app. How it should be done? in java you bundle your project into a single file, self containing and you put in into a server with some configuration. what about node.js?
Should i just copy the whole directory with sources and node_modules to production machine and use systemd, pm2 or other process manager to just run it? but i heard some of the dependencies might be system-dependend so they may work incorrectly
or should i copy only sources and run npm install --production on the production machine? but this way the deployment is only possible when npm repositories are online. also it takes time to build the application and it has to be done on all machines in the cluster. also what about quickly rolling back to previous version in case there is some bug? again, time and online npm repos are needed
another option is to build a docker image. but it seems awkward that the only way to easily and safely deploy the app is using third party technology
how it's being done in real life scenarios?
sure don't copy the whole directory especially node_modules.
all the packages installed on your system should be installed with --save option example: npm install --save express if you do so you will have in your package.json the dependencies required for your project whether they are dev dependencies or production dependencies.
I don't know what your project structure looks like, but as a node application you have to run npm init . in your project to setup the package.json file and then you can start adding your dependencies with --save.
usually we use git
version control system
to deploy to the server, first we push our code to a git repository then we pull from it to the server git
you have to add .gitignore in your project and ignore node_modules from being committed to your git repository.
then you can pull to your server and run npm install on the server. and sure you need to launch your web server to serve your application example ngnix
you can try Heroku for an easy deployment, all you have to do is to setup your project with Heroku, and when you push your code, Heroku manages the deployment . Heroku

How to get heroku to detect nodejs buildpack?

I am trying to deploy a web app to heroku but keep getting this error:
`-----> Failed to detect app matching https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/nodejs.tgz buildpack`
Here is a simplified look my app file structure:
myProject
|__server
|__server.js
|__react_component_1
|__react_componet_2
|__styles</p>
The express server is the server.js inside the server directory and it will the entry way to my app.
It seems like this question has been asked many times before and I've read all the answers, here's what I have tried:
I am deploying from the root folder, myProject, which did not have a package.json file. I've tried npm init to set up a package.json so heroku can detect the app as nodejs. I've also made sure that package.json is being tracked by git. I've made a Procfile: web: cd server && npm run start. I have run the command in the cli to set buildpack: heroku buildpacks:set heroku/nodejs but so far none of it has worked. I've also tried buildpacks:clear after setting everything up to see if heroku can automatically detect buildpacks now that I have a package.json.
Any help is appreciated, thank you.
According to Heroku's relevant documentation on Node.js buildpacks:
The Heroku Node.js buildpack is employed when the application has a package.json file in the root directory.
Based on your Procfile content, web: cd server && npm run start, that looks like you ran npm init inside the server directory, not the root directory.
I think if you move package.json and the node_modules folder one directory down to the root, the buildpack issue will be resolved. Just make sure to change your Procfile to web: npm run start because it would be the same directory now.

Deploying App on heroku node command not found

I have basically modified this app
https://github.com/heroku/node-js-getting-started.git
Now am trying to deploy in Heroku
My Procfile has this line
web:node index.js
And when I run this command locally,there are no probs..
However if I try to open the link in my browser after following all the steps in https://blog.risingstack.com/node-hero-deploy-node-js-heroku-docker/
I get an error
On checking the logs using heroku logs command I am getting 'node command not found'
Anyone knows the prob?
P.S : I tried changing Procfile contents to npm start but that doesnt launch index.js in the browser.
I suspect that you have not set the buildpacks. Buildpacks tells heroku which kind of application is yours.
Use the below command to set the application of type nodejs.
heroku buildpacks:set heroku/nodejs
And make sure that you have a package.json file in the root of the project which is read by heroku to install the project dependencies.
Why don't you try this below in your Procfile.In my case it runs nicely.
web npm install
You just need to add nodejs buildpack on heroku settings app,
after that you will be able to use npm commands.

Local or Private NPM module when deploying to Heroku

I have a node app that has a local npm module npm link ./local and I'm trying to deploy the app to heroku. Heroku runs npm install when I deploy, but npm link's aren't saved in package.json so my local module is missing.
I'm new to heroku and Procfiles, I'd like to run a script or just run npm link ./local before on the heroku box.
Alternatively I could put the module on github as a private repository and link it from there. But as far as I know Heroku isn't able to download private repo. Can I give Heroku access to my github repository via keys so that it could download it?
I'd love for somekind of solution! Anything!
I think you need yo put modules in node_modules folder and push that to heroku
Procfiles are easy to maintain and heroku will read that
I have sample Procfile like
web: bin/hubot -a campfire
Even heroku also says that best is to include node_modules into repo so you can just include your local packages into that.
See more here Heroku Node Deploy

Resources