Heroku saying I don't have Procfile - node.js

basically, i have procfile (without .txt) and it says i dont, so i cant configure dynos on heroku
here is how the repository is like:
https://i.stack.imgur.com/tVYT0.png
the text in procfile:
worker: node bot.js
i am horrible at this and i never used StackOverflow so yeah- if you reply to this use an easy language
(this is a discord.js bot)

Here's some stuff that you might want to try,
1: Making sure that your document is named .Procfile (capital P and . before)
2: Checking build logs for errors
3: Deleting and re-creating your procfile
Also you should be using worker for a discord bot.

Related

Deploying Vue.js + Express + MongoDB App to Heroku

So I've been at this for two days now and can't figure it out. I'm trying to deploy a Vue front end and express back end app to Heroku.
In my root folder I have a "public" folder which contains the front end and "server" folder for the back end.
In the root directory's package.json, the start script is
"start": "npm run pull && start npm run f && start npm run b",
"pull": "git pull",
"f": "cd ./public && npm run serve",
"b": "cd ./server && npm run dev"
This works perfectly fine for me to run locally, and even works with heroku locally as well using heroku local web but when I try to actually push to heroku using git push heroku main it doesn't even get past the git pull claiming:
fatal: not a git repository (or any parent up to mount point /)
I've tried simply getting rid of the git pull, but that just leads down a rabbit hole of other errors I've been trying to figure out for days and I'm hoping I'm just being dumb and missing something obvious. Any help would be greatly appreciated.
I'm going to try and list some things I've tried here:
Setting the heroku remote repository heroku git:remote -a heroku-name-here
Didn't change anything, pretty sure I already have this correct
Removing the git pull
Led to heroku not recognizing "start" sh: 1: start: not found
Removing the 'start' after git pull
Led to vue-cli-service not being found
Literally separating the back and front end into 2 separate repositories and 2 separate heroku things
This seemed to get the back end functioning, but the front end didn't seem to work. Unfortunately I don't remember exactly why but can try again if it would be helpful
All 3 comments from here: How to solve vue-cli-service: not found proplem on heroku?
I kind of fixed it kind of. Here's what I did
So I went back to the approach of kind of keeping them separate. I started by getting the server up and running.
In Heroku, I added the buildpack: https://github.com/timanovsky/subdir-heroku-buildpack.git BEFORE the heroku/nodejs buildpack to allow me to use a subdirectory rather than the whole repo
In Heroku settings, I added the config var PROJECT_PATH with the value server - In this case, server was the sub-directory immediately under my root
In vue.config.js of my front end, I changed the outputted build path to go INTO my server folder, using outputDir: path.resolve(__dirname, "../server/front-end")
In mongodb, under "Security" in "Network Access" which can be found towards the left in the navigation, I added the IP address 0.0.0.0/0 which I believe basically lets anyone access it. This might not be the most secure but it works.
Finally, this basically merged all my routes together which causes chaos because if I had a front end route /test-route and a back-end route /test-route it would like break which made sense. So I simply changed my index.js back end routes to go to /api/ instead of / so kind of like this
const mutators = require("./routes/mutators");
app.use(router.use("/api/", mutators));
Then at the end of my index.js file, I added
app.route("/*").get(function(req, res) {
res.sendFile(path.join(__dirname + "/front-end/index.html"));
});
so that front end routes like /test-route would then actually go to the site.

'heroku local' cannot find module 'load-foreman-procfile'

I'm trying to run Heroku applications locally via 'heroku local,' but a missing module error is occurring in the Heroku CLI. Is this a Heroku bug that just needs to be reported or is there something wrong with how things have been setup on my machine (mac)? Any suggestions are appreciated.
In order to ensure my application isn't the problem, I've been debugging this issue with the node application Heroku provides in its getting started guides. Meaning, it already has a Procfile that can be run using default settings.
Things I've tried:
Re-install node modules for both application and CLI
Re-install the Heroku CLI
Here's the error:
node-js-getting-started [master] :> heroku local
Error: Cannot find module '../../load-foreman-procfile'
at Object.<anonymous> (/usr/local/Cellar/heroku/7.26.1/libexec/node_modules/#heroku-cli/plugin-local/lib/commands/local/index.js:5:18)
The file for the route above requires a 'load-foreman-procfile' like so:
const Procfile = require('../../load-foreman-procfile');
That require path doesn't lead to a to file by that name. In fact, this is the only reference to 'load-foreman-procfile' I can find in '/usr/local/Cellar/heroku/7.26.1'.
Rather than the error code above, I would expect heroku local to yield a running local server started via my Procfile.
I got the same error running heroku-cli v7.26.0. I switched to their edge channel (currently v7.26.2) and heroku local worked for me after that.
like #sophon mentioned - updating from v7.26.0 to v7.26.2 solved this for me. heroku update on mac did the trick.

What heroku Procfile for parse server

Completely new to heroku, profiles and node.js. I'm running Parse Server hosted on Heroku and I'm trying to get kue running in order to do scheduled jobs.
To achieve that I need to add a worker. And to do that, I need a Procfile. But I don't know what to put in it.
This seems to work fine :
web: node index.js
worker: node queue.js
Where index.js is the index.js file of parse server and I have my queue related code in queue.js. Hope it'll help !

Using Heroku Scheduler with Node.js

There is literally no tutorial about using Heroku Scheduler with Node.js. Assume that I have a function called sayHello() and I would like to run it every 10 mins. How can I use it in controller. In ruby you write rake function_name() however no explanation made for Node. Can I write '/sayHello' or I should do extra configuration?
Create the file <project_root>/bin/say_hello:
#! /app/.heroku/node/bin/node
function sayHello() {
console.log('Hello');
}
sayHello();
process.exit();
Deploy to Heroku and test it with $ heroku run say_hello then add it to the scheduler with task name say_hello.
Explanation
Take say_hello.js as an example of a Node.js script that you would normally run using $ node say_hello.js.
Turn it into a script by
removing the .js ending
inserting the 'shebang' at the top: #! /app/bin/node [1][2]
moving it into the bin directory [3]
[1] Read about the shebang on Wikipedia.
[2] The node executable is installed in app/bin/node on Heroku. You can check it out by logging into bash on Heroku with $ heroku run bash then asking $ which node.
[3] Heroku requires scripts to be placed in the bin directory. See Defining Tasks in the Heroku Dev Center.
I agree that the Heroku documentation for scheduling tasks is not very clear for anything other than Ruby scripts. I managed to work it out after some trial and error.
A better approach is to define your schedule file called for example worker.js with following content:
function sayHello() {
console.log('Hello');
}
sayHello();
and then in the heroku schedule, you just write node worker like you define it in the Procfile and that's all!
Christophe's answer worked for me until I needed to pass a parameter to the script, at which point it failed. The issue is that node should not be specified in the task. Here is how exactly to get it working:
In your Procfile, define a process type for your script. See below for a typical Procfile with a web process and, for running "scheduled_job.js", a second process type imaginatively named "worker".
web: node app.js
worker: node scheduled_job.js
In the Heroku scheduler's Task column, just enter the name of the process type ("worker" in this example) with or without parameters. Don't enter 'node' before it. Heroku shows a dollar sign in front of it, so examples of a valid setup would be $ worker (run without arguments) or $ worker 123 abc (to execute scheduled_job.js with arguments "123" and "abc")
I am confused that nobody tried:
$ heroku run node yourScript.js
So put this in Heroku Scheduler
node yourScript.js
Worked for me.
PS: be sure to import everything your script needs.
Following steps work in my situation.
In the root folder add worker.js file.
In worker.js. Write an simple function, like above.
function sayHello() {
console.log('Hello');
}
sayHello();
Go to heroku Scheduler add-ons. Click 'add new job' and type 'worker' in the field. Then set time interval and click save.
Here are something should notice
After update works setting.If using above example, you can use heroku run node worker.js to check if it work. It should be show 'Hello' in your terminal.
I use express-babel starter for my node.js project.
Thnks so much for the previous answers here.
I found the following worked for me where feed.js is the script to run as a job on Heroku.:
<PROJECT_ROOT>/bin/feed.js
The contents of feed.js start with:
#!/usr/bin/env node
async function mediumFeed() {
await fetch('https://medium.com/feed/stokedinfluence')
And end with:
}
mediumFeed();
And on Heroku the job is defined as node bin/medium_feed.js:
To run the node js script locally feed.js you can use from the root of your project directory node bin/feed.js and to run via heroku you can use heroku run feed.js --app <APP_NAME_NOT_PIPELINE_NAME>. When using heroku command, this will run the job from the server where as running node bin/feed.js will run locally. Run locally to test and verify the code works, once deployed verify it works with the heroku run... command

ERROR: Procfile does not exist, and problems starting web processes

So, I'm currently following this tutorial: https://devcenter.heroku.com/articles/nodejs to start a simple Node.js app. I've got to the part where foreman is used to run the app locally (under Declaring process types with Procfile), and I'm getting an error telling me that the Procfile does not exist. My Procfile is in the same directory as my code, etc. All of the steps up till now have been fine. I skipped past this part in the tutorial to try and run the application on Heroku, but this line heroku ps:scale web=1 under Visit your application tells me that there is "No such type as web"... I'm using Windows to develop my app. Any help would be much appreciated. :-)
EDIT: web: node web.js is the contents of the Procfile, and I'm following the tutorial so I assume it's being committed... could you check the tutorial please and tell me if it is?
I had also received the Procfile does not exist error. The issue with mine was that I had left the '.txt' extension on the file. Once I removed the file extension and ran the foreman start it worked perfectly, hope this help =)

Resources