Deploy Node.js app on heroku

Signup/Signin on heorku

https://herokuapp.com/

Login from terminal (Make sure you have installed heroku cli – https://devcenter.heroku.com/articles/heroku-cli#download-and-install)

heroku login

Create app.js

const express = require("express");
const app = express();
const port = 8080;

app.get("/", (req, res) => {
    res.send("Hello Heroku");
})

app.listen(process.env.PORT || port, () => {
	console.log("listening 8080...");
});

process.env.PORT this will be provided by heroku server

Test locally by running following command

node app.js
OR
nodemon app.js

If you get any error e.g. module not found you can install those module using npm

npm install <module_name>

To find installed module version

npm view <module_name> version
e.g.
npm view express version

Create package.json

{
	"scripts" : {
		"start" : "node app.js"
	},
	"dependencies": {
		"express": "4.17.1",
		"mongoose": "5.13.3",
		"cors": "2.8.5"
	}
}

Run following command from terminal

#onetime
git init
#onetime
heroku create <yournewappname>

Run git commands

git add .
git commit -m 'msg'

#to verify origin
git config -l

#if you are not able to see url and fetch then run git remote add origin 
#remote.heroku.url=https://git.heroku.com/project.git
#remote.heroku.fetch=+refs/heads/*:refs/remotes/heroku/*
#git remote add origin heroku_git_url
#git push origin master

git push heroku master

Once app is deployed it will show you an url which you can access publicly from internet.

To see error logs

heroku logs --tail

26 Replies to “Deploy Node.js app on heroku”

  1. Hi my family member! I want to say that this post is amazing, great written and include approximately all vital infos. I would like to peer extra posts like this .

  2. Hello there! This is my 1st comment here so I just wanted to give a quick shout out and say I really enjoy reading your blog posts. Can you suggest any other blogs/websites/forums that cover the same topics? Thanks a lot!

  3. Приветствую! Сегодня затронем тему — сколько стоит ПВХ крыша. Дело в том, что: первоначальные затраты выше — зато экономия потом. Нужна смета — обращайся к: https://montazh-membrannoj-krovli-spb.ru. Какие результаты можно достичь: ПВХ не дёшев, но служит 30 лет. Допустим постоянно латаешь — то есть мембрана выгоднее. Основные этапы: считай на перспективу. Резюмируем: высокоэффективный инструмент — экономия в долгосрочной перспективе.

  4. Приветствую! Разберём самые актуальные — монтаж в холода. Здесь такой момент: битумные материалы зимой нельзя. ПВХ монтируют круглый год — могу рекомендовать: монтаж ПВХ мембраны. Лично я знаю: монтаж ПВХ — возможна до -15°C. Например стройка не ждёт — соответственно можно работать зимой. На первом этапе профессиональное оборудование. Вместо заключения: это работает — крыша зимой реальна.

  5. Generally I do not read post on blogs, however I wish to say that this write-up very forced me to check out and do so! Your writing style has been surprised me. Thanks, very nice post.

  6. I blog frequently and I really appreciate your information. This great article has really peaked my interest. I am going to take a note of your website and keep checking for new information about once a week. I opted in for your RSS feed too.

  7. Hello! Do you know if they make any plugins to safeguard against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?

  8. Woah! I’m really enjoying the template/theme of this blog. It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between usability and appearance. I must say that you’ve done a great job with this. Also, the blog loads super fast for me on Chrome. Superb Blog!

  9. Hi! Quick question that’s completely off topic. Do you know how to make your site mobile friendly? My blog looks weird when viewing from my iphone4. I’m trying to find a template or plugin that might be able to correct this problem. If you have any suggestions, please share. Cheers!

  10. Fantastic goods from you, man. I’ve understand your stuff previous to and you are just too fantastic. I actually like what you’ve acquired here, really like what you are stating and the way in which you say it. You make it entertaining and you still take care of to keep it wise. I can not wait to read far more from you. This is really a tremendous web site.

  11. Hello, i think that i saw you visited my weblog thus i came to “return the favor”.I am attempting to find things to enhance my site!I suppose its ok to use some of your ideas!!

  12. Hey! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

Leave a Reply to winhq Cancel reply

Your email address will not be published.