I want to deploy a MERN app on heroku. My git folder structure is like this
Repo
|
|---Frontend
| --src
| --package.json
|
|
|---Backend
| --src
| --package.json
|
|--readme.MD
I am unable to find heroku deployment methods similar to this folder structure and other methods do not seem to work for me. Steps on how to deploy my project would be appreciated.
As per the Heroku documentation, you cant deploy frontend and backend like this on a Single Heroku dyno.
According to many communities and experts, Heroku's model is to run one app per dyno (and often many dynos for a single app).
But wait, there is a case in which two servers are deployed to a single dyno and it worked too. You can check it here: https://medium.com/#nadayar/heroku-fu-multiple-servers-on-one-dyno-6fc68d57b373
Hope this solves your problem!
send all server files one level up...
and then in package.json of your server write this under "scripts"
"heroku-postbuild": "npm run instal-client && npm run build",
"instal-client": "cd ../client && npm install",
Related
I am trying to host a discord bot on Heroku (Discord JDA, Maven). I do this by connecting to Github and then deploying. The bot 'deploys' (view attachment) but doesn't actually work (view attachment).
What could I be doing wrong, or has anyone else come across a similar issue?
Quick and dirty way to deploy it:
You'll need to setup a Procfile, extensive info on that right here: https://devcenter.heroku.com/articles/procfile
The procfile is basically a file with no extension that tells the dyno how to execute your program.
A simple
worker: java $JAVA_OPTS -jar <PATH_TO_JAR>
will work fine if you don't need more config, refer to that link for more.
You can then deploy it like this (Good to have procfile and jar on the same directory):
$ heroku deploy:jar -a <YOUR_HEROKU_APP_NAME> --jdk <JDK_VERSION> --jar <PATH_TO_JAR> -i Procfile
Then to start it just do (Assuming you want a worker dyno, which is what discord should need)
$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=1
Then stop it with:
$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=0
I've found this is much simpler than using git, especially if you're doing tests or simple/quick stuff.
Possible solutions:
Set up a Procfile. A Procfile basically tells Heroku what command to run when your app is deployed. Inside the Procfile, write worker: node index.js. Also, make sure Procfile has a capital "P".
Set up package.json.
npm init
Then just skip through the set up and your file should be automatically created. IMPORTANT. In your package.json file, add your node and npm versions.
node -v
npm -v
Then go an type this in your package.json.
"engines": {
node: "your-version-here"
npm: "your-version-here"
}
Then try deploying your app to Heroku again. Also, make sure you have the "nodejs" buildpack set up for your app. Run it and test the discord bot.
First thing i am very new in Vue, adonis and heroku. so please tell me all the steps in answer
i have a project build in vuejs(frontend) and adonisjs api-only and i want to deploy this project on heroku with postgresql database.
What i am done till now:-
1). create a heroku account
2). create a project on heroku
3). upload frontend dist/ folder on heroku using these command
git add --all
git commit -m "initial commit"
git push heroku master
And my frontend run perfectly but i don't know how to deploy backend and how to create database
in heroku.
my working directories are
To deploy the back-end application you can do the same steps as you did for the other application.
Here's what's changing:
Add database with heroku add-ons (https://elements.heroku.com/addons/heroku-postgresql)
! When adding the add-on new heroku environment variables are created. (If they do not appear, see below)
Interesting things to know:
To execute Adonis commands : node ace <your_command> (node ace migration:run)
I advise you to use the heroku environment variables. Don't forget to add the variable ENV_SILENT = true to avoid errors because of the.env file.
Get connection db informations: (on your postgresql add-on):
Some additional information
Personal project deployed on heroku (.gitlab-ci.yml) : https://gitlab.com/CrBast/website
Interesting article : https://scotch.io/tutorials/deploying-adonisjs-apps-to-heroku
If my explanations are not clear, don't hesitate to tell me :)
I'm trying to deploy a Progressive Web App version of my Ionic 2 project to Heroku but it doesn't seem to work. What I'm trying is to use "Ionic build browser --prod" and then deploy the www folder, but I'm not getting any response from Heroku (Seems that nothing has being deployed)
The steps you are supposed to take:
Ionic build browser --prod - creates the main.js file to be deployed
Go to .gitignore file and remove the mentions of www/ so git picks it up and add these two lines so platforms browsers folder is picked up
platforms/*
!platforms/browser/
!platforms/browser/www
!platforms/browser/www/plugins
Add these 2 libraries to your package.json (don't forget to run npm install)
"connect": "^3.5.0",
"serve-static": "^1.11.1"
Add a start to your npm scripts in package.json
"start": "node server.js"
Add server.js to your project folder with the following code:
var connect = require('connect'),
serveStatic = require('serve-static');
var app = connect();
app.use(serveStatic("platforms/browser/www"))
app.listen(process.env.PORT || 5000);
Please note this code is only for ionic apps and not normal angular apps.
At this point you can write npm start or node server.js in your cmd and you can test to see how it will run.
Commit your code to heroku git using git push heroku master. Please note to have the heroku git on your remote list. You may do git remote -v to check if thats the case. If not get the url from the website and add it.
Optional - Put the www/ folder back in .gitignore and git rm --cached -r ./www to delete them from your git. This is so your co workers wont have merge conflicts on your main.js everytime you commit. The same for platforms/browser.
You are supposed to see heroku installing and deployed a node application in your enviornment after pushing to their git
NOTE If you are using Heroku you could probably do this with Heroku builds rather than playing with your git. https://github.com/heroku/heroku-builds
An update, as i ran the same task today:
It may be preferable to avoid
Adding and maintaining "server" code along with your app.
Pushing the built app (www/) in your version control system.
You can rely just on the heroku buildpacks. To do that you would need two buildpacks:
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/heroku/heroku-buildpack-static.git
Your app will be detected first as node app and will build, and later as a static site and served.
First, build the app up on heroku, don't add www to your version control system:
The first buildpack will detect your app as node app, and run the build after the postbuild script.
you need to add this line to you package.json scripts:
"heroku-postbuild": "ionic build --prod"
and add the ionic cli to your dev-dependencies so it can be available for heroku on the build process
npm install ionic --save-dev
Second, serve the static files generated:
The second buildpack will serve the static files generated in www. For that you need to tell the buildpack how to serve the files with a static.json file: (this one is somewhat equivalent to the config for firebase in the ionic docs)
/static.json:
{
"routes": {
"/**": "index.html"
},
"headers": {
"ngsw-worker.js": {
"Cache-Control": "no-cache"
},
"/build/app/**": {
"Cache-Control": "public, max-age=31536000"
}
},
"root": "www/"
}
Looks like the new Ionic doesn't generate the 'www/build/app/...' directory anymore, just added to be consistent with the above mentioned docs.
Just those two changes, along with the buildpacks are enough to run the PWA on heroku / dokku
I have a shiny app and want to deploy it to Heroku. I tried to follow the steps as mentioned in:
https://github.com/btubbs/heroku-buildpack-shiny
I created a git Git repository and put the R files into it. Then, I created an app in heroku and tell Heroku to use a custom buildpack for my app. But, I was not be able to enable Heroku websockets support.
Error is:
Couldn't find that feature.
I can't figure out how to deal with this problem. Is there any other way to deploy the shiny app to Heroku?
Have you seen https://github.com/virtualstaticvoid/heroku-docker-r?
Check out the example shiny app too. To specify additional dependencies, you can still use init.R.
To deploy using Docker, you might have to move your current Heroku app to a container stack. This can be done with the heroku stack:set CLI command:
$ heroku stack:set container
Here's a minimal example. Basically:
Create run.R file with the following
library(shiny)
port <- Sys.getenv('PORT')
shiny::runApp(
appDir = getwd(),
host = '0.0.0.0',
port = as.numeric(port)
)
Commit to git
Create a new heroku app with
heroku create --buildpack https://github.com/virtualstaticvoid/heroku-buildpack-r.git
git push heroku master
That's all there is to it.
Another way would be to deploy using Docker. I am not an expert, but it took me a couple of days to deploy an app using this soluation. Many tutorials exist and could bring you to achieving this.
I've an existing project that works fine on another machine, but I've just upgraded and from within the project development directory, everytime I run a heroku command I have to post-fix it with --app
I feel like I've missed an application setup stage, but I can't figure out what, as everytime it states:
Run this command from an app folder or specify which app to use with --app APP.
Help appreciated.
You can solve this by adding the Heroku app to your .git/config folder.
If you are in the root of your project, run the following command:
git remote add heroku git#heroku.com:appname.git
This will set a line in your .git/config file which the heroku command line tool uses to figure out what app you're using :)
In other words, your local repo doesn't have Heroku app URL configured against an app name
Similarly what we do with git remote add ( we pass git URL as a destination for push/pulling of code )
that how our git know which repo/URL to hit (push/pull from )
Heroku also follows the same method/process.
All you have to do is add Heroku app URL (so that ur Heroku command have a reference for app URL )
it will know against which URL you are running your command against
To confirm if remote named Heroku has been set for your app:
git remote -v
if not configured or if you want it for an existing app
heroku git:remote -a app_name
it's a way to link your folder to the Heroku app
The Heroku recommended way:
heroku git:remote -a my-heroku-app-id -r what-i-want-to-call-it
Source: https://devcenter.heroku.com/articles/git
Run this command from an app folder or specify which app to use with --app APP
The other answers address the first part of that statement, it is perfectly acceptable to run heroku commands in any directory. For example I have a customer facing front end project /front-end and a rails based /back-end project. I often work in the /front-end directory and if I have to connect to the production database I'll run heroku run rails c -a back-end. After I exit irb then I'm back in my desired directory.