feathers
feathers copied to clipboard
How to Deploy a FeathersJS Rest-Api on Heruko?
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 https://github.com/feathersjs/docs/issues/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 !!!
NODE_ENV has to be set to production via the Heroku CLI or in the application settings:
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.
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?
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.
Just tried this out on my own. With a newly generate feathers app, the step to make it deployable on Heroku are
- Change
const server = app.listen(port, hostname)
to
const server = app.listen(port)
- Set the NODE_ENV variable to "production"
Everything has worked well, thank you all for your support.
NOTE for typescript projects you should change your scripts to build before Heroku prunes devDependencies
"heroku-postbuild":"yarn run compile",
"start": "node lib/",
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
@pankajxeine I think you should check outDir in tsconfig.json if its "./lib"
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