Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Deploy a FeathersJS Rest-Api on Heruko? #1647

Open
pm-dan opened this issue Oct 25, 2019 · 10 comments
Open

How to Deploy a FeathersJS Rest-Api on Heruko? #1647

pm-dan opened this issue Oct 25, 2019 · 10 comments

Comments

@pm-dan
Copy link

pm-dan commented Oct 25, 2019

I already uploaded my application to my github repository.

Heroku detects every change I make in my rest-api / branch and automatically deploys it.

I have already read all the information about this but I have not found anything to solve my problem.
e. g feathersjs-ecosystem/docs#66 or
https://stackoverflow.com/questions/47270219/deploy-feathersjs-app-on-heroku and many more...

I tried to do it as if it were a normal nodejs/express application.
I already changed the port "const port = process.env.PORT || app.get('port');"

I also put in the .env file"NODE_ENV = production", (I also tried this with "NODE_ENV = development")

Procfile has the command "web: yarn dev" (I also tried this with "web: node src/" and web: node src/index.js and web: node src/app.js)

But nothing absolutely nothing makes my rest-api work.
I'm already very desperate and I don't know what else I could do.
Please help !!!

@daffl
Copy link
Member

daffl commented Oct 25, 2019

NODE_ENV has to be set to production via the Heroku CLI or in the application settings:

Screen Shot 2019-10-25 at 9 59 09 AM

@pm-dan
Copy link
Author

pm-dan commented Oct 28, 2019

Thanks for your answer.
I will try to deploying as you advised me.
When I finished it I sent you a couple of screenshoots.
Thanks and a good day.

@harijoe
Copy link

harijoe commented Dec 2, 2019

I noticed the latest feathers generator adds the hostname to app.listen :

const server = app.listen(port, hostname);

This was causing an EADDRNOTAVAIL error on a freshly generated feathers application, deployed to heroku. Changing it back to:

const server = app.listen(port);

fixed it. Maybe that's the reason why it doesn't work for you @pm-dan?

@daffl
Copy link
Member

daffl commented Dec 2, 2019

I noticed the same thing. I think I'll revert that PR and make a new generator release. Also, a Cookbook entry for Heroku deployment would still be a very welcome contribution.

@fulminmaxi
Copy link

Just tried this out on my own.
With a newly generate feathers app, the step to make it deployable on Heroku are

  1. Change
const server = app.listen(port, hostname)

to

const server = app.listen(port)
  1. Set the NODE_ENV variable to "production"

@pm-dan pm-dan closed this as completed Mar 12, 2020
@pm-dan
Copy link
Author

pm-dan commented Mar 12, 2020

Everything has worked well, thank you all for your support.

@daffl daffl reopened this May 7, 2020
@MohammedFaragallah
Copy link

NOTE for typescript projects you should change your scripts to build before Heroku prunes devDependencies

    "heroku-postbuild":"yarn run compile",
    "start": "node lib/",

@pankajxeine
Copy link

getting error during feathers api deployment in heroku.

State changed from crashed to starting
2020-08-17T02:02:11.272095+00:00 heroku[web.1]: Starting process with command npm start
2020-08-17T02:02:14.648085+00:00 heroku[web.1]: Process exited with status 1
2020-08-17T02:02:14.684799+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-17T02:02:14.462391+00:00 app[web.1]:
2020-08-17T02:02:14.462413+00:00 app[web.1]: > [email protected] start /app
2020-08-17T02:02:14.462413+00:00 app[web.1]: > node ./lib/index.js
2020-08-17T02:02:14.462414+00:00 app[web.1]:
2020-08-17T02:02:14.587669+00:00 app[web.1]: internal/modules/cjs/loader.js:638
2020-08-17T02:02:14.587670+00:00 app[web.1]: throw err;
2020-08-17T02:02:14.587671+00:00 app[web.1]: ^
2020-08-17T02:02:14.587671+00:00 app[web.1]:
2020-08-17T02:02:14.587671+00:00 app[web.1]: Error: Cannot find module '/app/lib/index.js'
2020-08-17T02:02:14.587672+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
2020-08-17T02:02:14.587672+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:562:25)
2020-08-17T02:02:14.587672+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
2020-08-17T02:02:14.587673+00:00 app[web.1]: at startup (internal/bootstrap/node.js:283:19)
2020-08-17T02:02:14.587673+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
2020-08-17T02:02:14.593522+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-08-17T02:02:14.593872+00:00 app[web.1]: npm ERR! errno 1
2020-08-17T02:02:14.596439+00:00 app[web.1]: npm ERR! [email protected] start: node ./lib/index.js
2020-08-17T02:02:14.596542+00:00 app[web.1]: npm ERR! Exit status 1

Please help me whats wrong i m doing. below is script command

"heroku-postbuild": "npm run compile",
"start": "node ./lib/index.js",

thanks

@MohammedFaragallah
Copy link

@pankajxeine I think you should check outDir in tsconfig.json if its "./lib"

@cirosantilli
Copy link

I managed to get the feathers-chat app running on Heroku PostgreSQL BTW which might be of interest: https://cirosantilli-feathersjs-chat.herokuapp.com/ Overview: https://stackoverflow.com/questions/47270219/deploy-feathersjs-app-on-heroku/66723974#66723974 Branch: https://github.com/cirosantilli/feathers-chat/tree/sequelize-pg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants