How do I deploy an Angular.js app? - node.js

This may be a stupid question, but I'm wondering what platform I should use to deploy my Angular.js app? I tried using Heroku but got a "no Cedar-supported app detected" error. Any thoughts?
UPDATE
I'm trying to serve this to heorku as a Node.js application, but still can't seem to get it working. There's a web-server.js file in the root directory of my application and I reference it in my Procfile here:
web: node web-server.js
And here's my package.json file, also in the root directory:
{
"name": "medicare-data",
"version": "0.0.1",
"dependencies": {
},
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"respository": "medicare-data",
"author": "sararob"
}
I'm getting a "slug compilation error" in my heroku logs. Thoughts on why this might not be working?

You can run an Angular app on heroku if it is served as a node.js application. Usually, when you start working with Angular seed, there is already a node webserver script in the project. I believe if there is a package.json file in the root, heroku will detect and run it as a node.js application. I'll come back and update this answer with more detail shortly.
UPDATE
From the Heroku docs (and I am no expert), it has this passage after the deploy section: https://devcenter.heroku.com/articles/nodejs#visit-your-application
which basically tells you to make sure you have one dyno running. You can do that either through the web app under the settings of your app or you can run this:
$ heroku ps:scale web=1
To see if the process is running, do
$ heroku ps
=== web: `node web.js`
web.1: up for 10s

I bet if you look at your logs you'll see something like this:
2013-08-26T12:51:18.257006+00:00 heroku[web.1]: Starting process with command `node scripts/web-server.js`
2013-08-26T12:51:19.109974+00:00 app[web.1]: Http Server running at http://localhost:8000/
2013-08-26T12:51:34.369092+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path=/ host=cmwidget.herokuapp.com fwd="77.101.66.230" dyno= connect= service= status=503 bytes=
2013-08-26T12:52:19.445974+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
It means that your Angular seed app is using it's own port (8000), and Heroku doesn't allow this. You need to relinquish the assignment of the port number to Heroku.
Easily fixed. Modify scripts/web-server.js, and change this:
this.server.listen(port);
...to this:
this.server.listen(process.env.PORT || port);

I changed this line
var DEFAULT_PORT = 8000;
into:
var DEFAULT_PORT = process.env.PORT || 8000;
..and then it worked.
So I believe the reason is that heroku doesn't like your app running on port 8000.

Related

Heroku App rollback works but identical code does not - works perfectly locally

I have a Node.js app running a React front-end hosted on Heroku which is linked to a Github repository so that on push it redeploys the app. I have been using the app this way without problem for around a year now.
It works on Heroku Local, and running the node app locally without Heroku but I'm getting a 503 service unavailable error when I run a put request when running the app online.
2021-06-01T08:04:27.326913+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=PUT path="/api/auth/login" host=myapp.herokuapp.com request_id=9b84f5c5-def4-4dce-82d2-baf1bef3a9a8 fwd="90.215.204.78" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
Any pointers?
It was fixed by adding a Procfile with: "web:server/index.js" as well as specifying the Node version specifically changing the code in my package.json from:
"engine":"12.x",
to:
"engines": {
"node":"v12.18.3"
},
I think it is likely the package.json change that ultimately fixed the problem.

Heroku H12 Request Timeout Error on Express route executing Python script

I'm running into this major issue on my Heroku app: I have an Express route set up
as follows:
app.get('/recommendations/:data', (req, res) => {
let dataSplit = req.params.data.split("");
let dataInt = [];
dataSplit.forEach(char => dataInt.push(parseInt(char)));
function sendPrediction(dataInf) {
const process = spawn('python', ["./predict.py", dataInt]);
process.stdout.on('data', (data) => {
let jSonned = JSON.stringify(data.toString('utf-8'));
let chopped = jSonned.slice(1, jSonned.length - 3);
res.send(chopped.split(','));
});
}
sendPrediction(dataInt);
});
When I make the GET request to this route from the frontend component, it times out with an H12 error after 30 seconds as per Heroku's default behavior. Since this route works fine on my localhost, it leads me to believe that there is something wrong with the Python dependencies, as I can replicate the same behavior on localhost by deactivating my virtualenv. I know this isn't much to go by, but if anyone has seen something like this and can help I'd greatly appreciate it.
How can I figure out where the issue is?
Here is the error from Heroku logs:
2018-04-30T17:17:27.175201+00:00 heroku[router]: at=error code=H12
desc="Request timeout" method=GET path="/recommendations/41231" host=what-
doxd.herokuapp.com request_id=2249d6ac-a389-40c1-8f64-8947796494a7
fwd="12.23.56.98" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0
protocol=https
Issue resolved: I needed to specify Python 2 and not let heroku default to python 3
First of all, you should attach your heroku logs to the question, so that we can see what Heroku is complaining about.
In absence of Heroku logs, I am guessing that you might not have a python buildpack defined for your app. Since your web dyno is built with node/express, you presumably already have a node.js buildpack (which Heroku may have added to your app automatically for you, if you didn't add it explicitly).
In that case, you need to add a python buildpack. Otherwise, python is not included in your app's slug.
See here for instructions on adding another buildpack to your app.

Heroku is giving me a 503 when trying to open my web app, works on local host

I am trying to deploy to heroku but get a 503 even though it runs on localhost. I am curious as to if my server is set up correctly as I am newer to programming. I hope anyone can point me in the correct direction as to where to look or provide a suggestion as I have spent countless hours on google to this point spanning a couple of weeks.
My main question is if I have set up my server correctly? I am not sure my listener will work for heroku and my .get are used for debugging on localhost when it was initially set up.
Also my full project is available here:
https://github.com/dirkdir/DerekDevSite
var express = require('express');
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/json', function(req, res) {
console.log("GET the json");
res
.status(200)
.json( {"jsonData" : true} );
});
app.get('/file', function(req, res) {
console.log("GET the file");
res
.status(200)
.sendFile(path.join(__dirname, 'app.js'));
});
var server = app.listen(process.env.PORT || 5000), function() {
var port = server.address().port;
console.log("Express is working on port " + port);
});
Logs:
2017-04-24T20:04:43.755866+00:00 app[web.1]: at Module._compile (module.js:542:28)
2017-04-24T20:04:43.755867+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-04-24T20:04:43.755868+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-04-24T20:04:43.755868+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-04-24T20:04:43.755869+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-04-24T20:04:43.755869+00:00 app[web.1]: at Module.runMain (module.js:604:10)
2017-04-24T20:04:43.755870+00:00 app[web.1]: at run (bootstrap_node.js:393:7)
2017-04-24T20:04:43.755871+00:00 app[web.1]: at startup (bootstrap_node.js:150:9)
2017-04-24T20:04:43.846556+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-24T20:26:31.826133+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=derekdyerdev.herokuapp.com request_id=609ef253-0a56-41ac-b877-1fb242f6f4e1 fwd="69.36.89.218" dyno= connect= service= status=503 bytes= protocol=https
2017-04-24T20:26:32.319732+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=derekdyerdev.herokuapp.com request_id=f2a34e62-9765-
You have the bracket on line 34 of your app.js file in the wrong place.
Since the function is a callback, it needs to be within the params.
Change that last block to this:
const server = app.listen(process.env.PORT || 5000, () => {
const port = server.address().port;
console.log(`Express is working on port ${port}`);
});
I also modified the Procfile to just this:
web: node app.js
After I modified that I was able to run locally, and I deployed it to my Heroku just to test, and it works fine :)
This may be helpful to someone.
My initial Profile content was this :
web : node server.js
and after changing it to this, it worked :
web:node server.js
The space between 'web' and ':' symbol was the problem. Weird though
I had a similar issue. Worked on localhost.. not when deployed to Heroku. My problem? I had cloned a project (node_modules too) and my package.json did not have express, minimist etc.. so it obviously failed.
Tip: When deploying, view the logs right away so you can see what's happening throughout the deployment process. Viewing the logs after it has failed will only show you the end of the logs...
Lastly, ensure you listen on the proper port. I do this (as others do too)
var serverPort = 8080;
. . .
var port = process.env.PORT || serverPort;
I just had the same error on my heroku app.
I installed cors locally and pushed only the file app.js to the repository and deployed it to heroku.
The error was actually that the cors package wasnt declared on my package.json (I only pushed app.js to github) so when heroku tried to call the app it caused an error because cors was undefined.
The point is, also check if the package.json is updated.
This Might help others
From Terminal Check out your Heroku Logs
Check out the error message
This might be possible that any npm module you have installed globally
Then just install that npm module locally.
Commit the updated package.json and package-lock.json file on git.
Then run git push Heroku master.
I had to do a couple of things before I could get my app running, I will list all of them in case it helps anyone.
1.) Make sure you specify the version of node in your package.json file like this
"engines": {
"node": "14.15.1"
}
2.) Make sure you have no errors in your Procfile, the below command worked for me
web: node server.js
3.) My server.js file was inside the src folder and that was the root cause for me, I had
to move it out of that folder and then it started working for me
I was struggling with similar problem then noticed quotation marks in my Procfile. When I removed them problem solved.
"web: node index.js" WRONG!
It must be without quotes:
web: node index.js CORRECT!
I had this same issue when deploying a Rails 6 API only application to Heroku.
I was getting this error when I try accessing the application in a browser:
Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail
Here's how I fixed it:
I ran the command below to check the application logs:
heroku logs --tail
Then I scrolled up within the logs to view logs from when the application server was started. Then I found this error:
2020-12-17T12:28:46.973736+00:00 heroku[web.1]: Process exited with status 1
2020-12-17T12:28:47.017905+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-17T12:28:47.028049+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-17T12:28:50.252842+00:00 heroku[web.1]: Starting process with command `bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-production}`
2020-12-17T12:28:53.969375+00:00 app[web.1]: Puma starting in single mode...
2020-12-17T12:28:53.969443+00:00 app[web.1]: * Version 4.3.7 (ruby 2.6.6-p146), codename: Mysterious Traveller
2020-12-17T12:28:53.969472+00:00 app[web.1]: * Min threads: 5, max threads: 5
2020-12-17T12:28:53.969505+00:00 app[web.1]: * Environment: production
2020-12-17T12:28:57.565417+00:00 app[web.1]: ! Unable to load application: SyntaxError: /app/app/policies/user_policy.rb:4: duplicated argument name
2020-12-17T12:28:57.565428+00:00 app[web.1]: def initialize(user, user)
2020-12-17T12:28:57.565429+00:00 app[web.1]: ^~~~
2020-12-17T12:28:57.565468+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.6.0/bin/puma)
2020-12-17T12:28:57.565510+00:00 app[web.1]: SyntaxError: /app/app/policies/user_policy.rb:4: duplicated argument name
2020-12-17T12:28:57.565510+00:00 app[web.1]: def initialize(user, user)
2020-12-17T12:28:57.565511+00:00 app[web.1]: ^~~~
I fixed the error in my code which was caused by a duplicated argument name, that is def initialize(user, user) in my Pundit gem policies.
In the policies file for Users (app/policies/user_policy.rb) in my application, I simply renamed:
def initialize(user, user)
to
def initialize(user, user_model)
and almost did the renaming at the other places in the app/policies/user_policy.rb file that user, user was defined to user, user_model.
I saved and then pushed it to production and that fixed the issue for me.
That's all.
I have run app on local environment. In the log I saw "Module can not found 'index.js'" I updated my main js "app.js" to "index.js" and update package.json for main js. Then push my code to Heroku again. it worked.

Node.js app works on foreman but not heroku. 404 Error

I'm using Yeoman/bower/grunt to build an angular app. The app runs perfectly on foreman. In my search of similar questions on stack most other people just forgot to create their Procfile or had mistakes in their app.js which ran the app. But I have both of those and I can't figure out what's wrong with them, such that foreman works and not heroku. When I deploy to heroku and open it I get this in the log:
2013-10-02T19:33:56.159151+00:00 heroku[api]: Deploy b417d22 by richardadavila#gmail.com
2013-10-02T19:33:56.202052+00:00 heroku[api]: Release v10 created by richardadavila#gmail.com
2013-10-02T20:38:51.350572+00:00 heroku[web.1]: Idling
2013-10-02T20:38:57.626159+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2013-10-02T20:39:02.097317+00:00 heroku[web.1]: State changed from up to down
2013-10-02T20:39:02.079612+00:00 heroku[web.1]: Process exited with status 143
2013-10-02T22:00:00.360769+00:00 heroku[web.1]: Unidling
2013-10-02T22:00:00.361135+00:00 heroku[web.1]: State changed from down to starting
2013-10-02T22:00:04.049439+00:00 heroku[web.1]: Starting process with command `node app.js`
2013-10-02T22:00:06.128657+00:00 app[web.1]: server started 40741
2013-10-02T22:00:06.164522+00:00 heroku[web.1]: State changed from starting to up
2013-10-02T22:00:07.479644+00:00 heroku[router]: at=info method=GET path=/ host=rickydavila-kpopbetter-s.herokuapp.com fwd="71.144.19.194" dyno=web.1 connect=9ms service=30ms status=404 bytes=22
No error (I probably don't fully understand the log), it just kills the app.
My Procfile says: "node app.js"
My app.js file that creates an express server to run the app is:
var express = require('express');
var path = require('path');
var app = express();
app.configure(function(){
'use strict';
app.use(express.bodyParser());
app.use(express.static(path.join(__dirname, 'dist')));
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
'use strict';
console.log('server started '+port);
});
Grunt builds the app to my dist folder which I reference above. Any clear mistakes above? When I open the heroku app url, the page states: Cannot GET /
Oh I also have scaled the dynos as some other questions failed to do. And to my knowledge I'm not hardcoding the port.
Figured it out. Always check your .gitignore file! I forgot to remove dist from the file and it hadn't been committed or pushed to heroku.

First Heroku deploy failed `error code=H10`

I deployed my app to Heroku. It's a node.js + express + socket.io app and this is the package.json file
{
"name": "game_test",
"author": "Ilya",
"description": "A test app for our board game",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "3.0.6",
"jade": "*",
"socket.io" : "*"
},
"engines": {
"node": "0.8.14"
}
}
This is the log I get:
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=
What does it mean?
Found solution for me here: Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
In my case my app crashed because I was hard setting the PORT, instead of using the port that heroku dinamicaly sets, which can be accessed with process.env.PORT
app.listen(process.env.PORT || 3000, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
I just had a similar issue with my app, I got the issue after a migration of the DB, after trying many options, the one that helped me was this:
heroku restart
(Using Heroku toolbelt for mac)
I had this issue, the only problem was my Procfile was like this
web : node index.js
and I changed to
web:node index.js
the only problem was spaces
In my case, i found same error because there is version difference of node and npm on my local machine and defined in package.json version.
"engines": {
"node": "0.8",
"npm": "1.2.x"
}
when i check using
node --version : v0.10.41
npm --version : 1.4.29
when i update my package.json to
"engines": {
"node": "0.10.41",
"npm": "1.4.29"
}
It works fine :)
in my case adding process.env.PORT || 3000 to my http server script, resolved.
My heroku log reported 'H20' error and 503 http status.
In my case there was no start command in the script section of package.json file.
When I created the package.json file with npm init I did not create a start script command.
So I went to the package.json file, under scripts I added a new entry:
"scripts": {
"start": "node index.js"
},
Saved it and uploaded to Heroku and it worked
In my case, my Procfile was pointing to the wrong file (bot.js which I previously used) so once I updated it, the error was gone.
Also check your database connection. I forgot to change my database connection from localhost and this crashed my app once it was pushed to heroku.
I faced this same problem and none of the answers above helped me.
What i did was run:
node --version
and in the package.json add the engines section with your node version:
{
"name": "myapp",
"description": "a really cool app",
"version": "1.0.0",
"engines": {
"node": "6.11.1"
}
}
upon using hapi18, I find taking out the "host" field and setting the port to:
port: process.env.PORT || 5000 did the trick.
Old Thread, but I fix this issue by setting PORT constant to process.env.PORT ||
For some weird reason, it wanted to search Env first.
I had a typo
const PORT = process.env.PORT||'8080';
used to be
const PORT = process.env.port||'8080';
If you locally start node server by nodemon, like I did, and it locally works, try npm start. Nodemon was telling me no errors, but npm start told me a lot of them in a understandable way and then I could solve them by following another posts here. I hope it helps to someone.
In my own case, i got this error because i refuse to add a Procfile to my node js app and my "main": "app.js" was initially pointing to another js file as main. so doing these chnages get it fixed for me
Password contained a % broke it for me.
In my case, I forgot to set database env for deployment.
you can set env by this command
(I'm using mLab for MongoDB server)
heroku config:set MONGO_URI='mongodb://address'
For me it was Package.json it was empty from dependencies even though i thought i did install them.. so I had to reinstall them with --save option in the end and verify they were added to the package.json.. and then push it again and it worked.
My port was set to config.httpPort which resolves to 80. I fixed it by doing this:
const PORT = process.env.PORT || config.httpPort;
app.listen(PORT, ...)
Thanks a lot, it wasted me a lot of hours last night.
In my case I had code=H10 and status=503 because my
Procfile:
web: node build/server.js
and I included /build in .gitignore
My start command had env-cmd -f ./config/prod.env node index.js.
after changing to: node index.js it got fixed.
I got the same issue, the problem was my Profile was like this:
web: gunicorn__init__:app
Notice with the above there was no space between gunicorn and __ init __
instead of
web: gunicorn __init__:app
in my case the problem solved by changing the order :
From :
app.listen(2000 || process.env.PORT);
to :
app.listen(process.env.PORT || 2000);
Just got this error and resolved it. For anyone who has tried the other methods and failed, do check your Procfile path. My server was in the backend folder yet I only typed web: node server.js. I resolved the error after changing it to web: node backend/server.js
The H10 error code could mean many different things. In my case, the first time was because I didn't know that Heroku isn't compatible with Sqlite3, the second time was because I accidentally pushed an update with Google analytics working in development as well as production.
I got the same above error as "app crashed" and H10 error and the heroku app logs is not showing much info related to the error msg reasons. Then I restarted the dynos in heroku and then it showed the error saying additional curly brace in one of the index.js files in my setup. The issue got fixed once it is removed and redeployed the app on heroku.
Older thread, but for me I didn't set my .env vars in the Heroku console.
i was using body-Parser that throw exception
const bodyParser = require('body-Parser')
//Bodyparser Middleware
app.use(bodyparser.json())
intead of using
//Bodyparser Middleware
app.use(express.json())
this resolved my issue
I want to register here what was my solution for this error which was a simple file not updated to Github.
I have a full stack project, and my files are structured both root directory for backend and client for the frontend (I am using React.js). All came down to the fact that I was mistakenly pushing the client folder only to Github and all my changes which had an error (missing a comma in a object's instance in my index.js) was not updated in the backend side. Since this Heroku fetches all updates from Github Repository, I couldn't access my server and the error persisted. Then all I had to do was to commit and push to the root directory and update all the changes of the project and everything came back to work again.
I struggle with the same error for hours, but I was able to solve it. I installed multer and aws-sdk as a devDependencies by mistake, instead of just dependencies.
So, anyone who has the same error, just double-check your package.json file.
Also, a small tip for the property of the engine in package.json.
enter code here
//The greater or equal operators will make sure that you use the right node
//version
//even if your current node is greater version than npm node
"engines": {
"node": ">= 0.8.14"
},
//insted of
"engines": {
"node": "0.8.14"
}
I was deploying python Django framework when I got this error because I forget to put my app name web: gunicorn plaindjango.wsgi:application --log-file - instead of plaindjango

Resources