Syntax error when start $ heroku open - node.js

I am new to Heroku and I am trying to deploy my first app onto Heroku.
I followed instruction, which were:
git init, add and commit my app's source code.
heroku create to create Heroku remote repo for my app.
git push heroku master to push my app's source code to heroku
heroku open
Problem happened when I tried to run heroku open, which was:
$ heroku open
(node:6192) SyntaxError Plugin:
heroku:C:\Users\hauph\AppData\Local\heroku\conf
ig.json: Unexpected string in JSON at position 72 module:
#oclif/config#1.6.33
task: runHook prerun
plugin: heroku
root: C:\Program Files\heroku\client
See more details with DEBUG=*
Image taken from that error
I checked file config.json at the direction as addressed above, and it was:
{
"schema": 1,
"install": "554c101b-d4de-496c-9768-710142ebfb20"
}
"skipAnalytics": false
}
So what did I do wrong here?
I would be grateful for any help.
Thank you very much!

I had the same problem. Not sure why it ends up corrupted, but the config.json should look like the following (get rid of the curly brace before skipAnalytics):
{
"schema": 1,
"install": "3265b92a-27f4-4adb-9c07-75d9213f0000",
"skipAnalytics": false
}

Your config.json contains invalid JSON (note the two closing brackets). Reinstall the Heroku CLI, and you should be in good shape.

I tried reinstalling but didn't work, just add curly braces in the config.json file.
{
}
Works perfectly now.

I had the same error when I tried to build on heroku as like below
(node:1179857) SyntaxError Plugin: heroku: /home/{...}/.local/share/heroku/config.json: Unexpected end of JSON input
module: #oclif/config#1.18.3
task: runHook prerun
plugin: heroku
root: /snap/heroku/4085
See more details with DEBUG=*
set git remote heroku to https://git.heroku.com/{...}.git
So I opened the config.json file from this path /home/{...}/.local/share/heroku/config.json and added blank curly braces
{
}
Then I run the command heroku git:remote -a {your project name} to set heroku git remote
Finally checked the config.json file and added valid json value automatically like this screenshot:
{
"schema": 1,
"install": "19975845-fr45-hfgt6-iu78-c27hgy243c46d",
"skipAnalytics": false
}
Finally set remote successfully. I hope it will make developers easier to deploy on heroku if this type of error comes.

USAGE
$ heroku apps:open [PATH]
OPTIONS
-a, --app=app (required) app to run command against
-r, --remote=remote git remote of app to use
EXAMPLES
$ heroku open -a myapp
# opens https://myapp.herokuapp.com
$ heroku open -a myapp /foo
# opens https://myapp.herokuapp.com/foo
Please visit heroku cli commands documentation here https://devcenter.heroku.com/articles/heroku-cli-commands

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.

nodejs and express with heroku im getting R10

thanks for taking time to help me
im deploying a nodejs express js project
these are the steps that i have done:
1- change the port to: process.env.PORT
code:
const PORT = process.env.PORT || 9000;
app.listen(PORT , function() {
console.log('Application is listening on 9000');
});
2- create Procfile with: web: node server.js
3- make sure in package json the npm start command points to "node path/server.js"
the server works locally
4- important note: I am sending an AJAX request from my front end to the server to get data
I have read on you documentation that i should add 0.0.0.0
$.ajax({
url: "0.0.0.0/hotels",
cache: false,
type: 'GET',
success: function(result) {
bla bla ....
}
});
also i have tried to add the url of heroku the one i get after creating
thanks in advance
have a great day
did not solve it yet but i organized some helpful heroku commands
useful commands
git remote -v
git remote rm heroku
heroku create
git push heroku master
heroku ps:scale web=1
heroku open
heroku logs --tail
heroku run bash
Your code there looks fine (except 0.0.0.0 -- just use a relative path like /). I would ensure you've actually pushed the changes you have there. If you run heroku run bash, do you see your Procfile? When you run node server.js in that environment, does it run successfully?
I've seen Heroku customers get stuck on an issue like this, when the reality is that the code they have locally wasn't properly sent to Heroku.
Hello #jmccartie thank you for replying but it still does not work
could it be the static __dirname? im starting to question every part of the code :D
I changed the path and just to make sure i understood correctly
it used to be : "http://localhost:9000/data/hotels"
now is: "/data/hotels"
would you mind taking a look at my code?
just double check the parts i mentioned
https://github.com/hibaAkroush/herokuNode
i will name the files to make it easier for you
1- Procfile in the root
2- server in server/index.js line 24
3- the front end (where im sending an ajax get request) client/home.js line 6
4- packagejson line 10: "start": "node server/index.js"
thanks
ok i fixed it ...
wohoo!
not sure which thing i made fixed it
but what i did was:
1- I moved the server to the root and of course changed the code a bit so it would still work than i tested it locally to make sure
2- pushed on github
3- added ./ to procfile so it became
web: node ./index.js
instead of web: node index.js
thanks everyone !

Deploying Hexo on Azure.. not sure what i'm missing

I recently decided to start a small blog for personal use (for now) on Azure. I started digging into the blogging framework Hexo. Now i got the (first) basics under control with starting a Hexo blog locally, but i want to push it to Azure.
I configured a basic web-app with a GIT connection for continuous deployment (https://github.com/lmeijdam/demo-repo). I tried a tutorial with a
server.js file
package.json
.gitignore
Above will result in a working response and installed node_modules... But from there i am really lost about my next steps...
I know you can create a package.json file and viewing my ftp client the package.json is there and also the node_modules folder with the correct modules installed. My package.json;
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"hexo": {
"version": "3.1.1"
},
"dependencies": {
"express": "*",
"hexo": "^3.1.0",
"hexo-deployer-git": "0.0.4",
"hexo-generator-archive": "^0.1.2",
"hexo-generator-category": "^0.1.2",
"hexo-generator-index": "^0.1.2",
"hexo-generator-tag": "^0.1.1",
"hexo-renderer-ejs": "^0.1.0",
"hexo-renderer-marked": "^0.2.4",
"hexo-renderer-stylus": "^0.3.0",
"hexo-server": "^0.1.2"
}
}
and i also found out you can deploy a Procfile to the GIT repo which Azure then uses, if you have no default file called server.js (https://github.com/yavorg/azure-node-starter/blob/master/Procfile)
And later a friend came with the tip to edit the procfile to write something like;
web: /node_modules/hexo/bin/hexo server instead of just the web: node server.js
unfortunately this just results in a default blanco webpage... http://lmnodetest1.azurewebsites.net/
Am i doing stuff wrong here or am i forgetting something at the start?
Per my experience, Hexo is a static blog website generator. You can follow these steps below to generate a website at the path "public".
$ hexo init blog
$ cd blog
$ npm install
$ hexo generate
Then, the "public" directory generated, and you can entry into this directory and run the command hexo server to browse http://localhost:4000 to explore your blog.
$ cd public
$ hexo server
For deploying the blog into Azure Website by using Git, you just need to create a local git repo by commanding git init at the "public" dir.
Please refer to the doc https://azure.microsoft.com/en-us/documentation/articles/web-sites-deploy/ to deploy it into Azure.
Best Regards.
Here are the steps that I do to run Hexo blog on Azure: http://the-coderok.azurewebsites.net/2015/09/16/Running-Hexo-blog-on-Azure/
It seems to me that the best part about using hexo is as a static site generator. The hexo server is really meant to give you a nice development environment where you can see your posts right away, but if you're publishing your site you'd wanna serve the statically generated content to remove node from the picture.
Hexo has hexo generate for that and you can get that to work nicely with Azure if you have a custom deployment script.
Here is a repo with 2 commits that you can git push to an empty site and it'll create a working static hexo blog:
First commit is just the result of hexo init blog
Second commit is the custom deployment script. You'd want to copy these 2 files to your own repo.
here is the exact parts that you'd need in your deploy.cmd for hexo.
note that the actual script in the repo has way more lines for proper error handling but this is just the gist of what you need
echo Handling Hexo deployment.
IF NOT DEFINED HEXO_PATH (
echo Setting HEXO_PATH to %HOME%\npm_tools\hexo.cmd
set HEXO_PATH="%HOME%\npm_tools\hexo.cmd"
)
IF NOT EXIST %HEXO_PATH% (
echo Hexo CLI isn't installed. Running 'npm install hexo-cli -g'
mkdir "%HOME%\npm_tools"
npm config set prefix "%HOME%\npm_tools"
npm install -g hexo-cli
)
echo Running 'npm install --production'
npm install --production
echo Running 'hexo generate'
%HEXO_PATH% generate
echo Copying static content to site root
"%KUDU_SYNC_CMD%" -v 50 -f "public" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
I took a quick look at your site. The issue appears to be that you have a server2.js file but no server.js file. Can you try renaming it in your repo and pushing again? That should at least get you past the first hurdle.

Deploying NodeJS application to Openshift

I have working SailsJS app that I want to deploy to Openshift, but as usual it doesn't go smoothly.
Here's what I did so far:
rhc app create myApp nodejs-0.10
rhc cartridge add mongodb-2.4
After these two, I can see that app is created and when I visit given URL, I got Welcome page.
I installed RockMongo, and I see that I can visit my mongodb as well.
Since I already have code, I proceed with following:
git remote add openshift -f <openshift-git-repo-url>
git merge openshift/master -s recursive -X ours
git push openshift HEAD
After I merge my existing code with remote openshift (like in commands above), things start to go wrong.
When I visit url to application, I receive 503 Service temporarily unavailable. If I visit RockMongo and try to login with given credentials, I receive
Unable to connect MongoDB, please check your configurations.
MongoDB said:Failed to connect to: 127.10.37.130:27017: Transport endpoint is not connected.
Also, in Applications Panel, status of my application is building (and stays like that for hours). After pushing code to openshift, application stopped, and after rebuilding it (automatically) I receive some errors, where the last one is
remote: An error occurred executing 'gear postreceive' (exit code: 34)
remote: Error message: CLIENT_ERROR: Failed to execute: 'control build' for /var/lib/openshift/538f1c205004461655000227/nodejs
Does anyone has idea what's going on?
Maybe I didn't set up ports, application url, db url properly? But then again, why RockMongo stopped working?
UPDATE
Here's my mongo config:
mongo: {
module: 'sails-mongo',
user: 'admin',
password: '********',
url: process.env.OPENSHIFT_MONGODB_DB_URL + 'surge'
}
Do I need to set up server_port = process.env.OPENSHIFT_NODEJS_PORT and server_ip_address = process.env.OPENSHIFT_NODEJS_IP as well?
I have some server.js file in root of my application, and I see that these variables are used here.
Here's what I get if I run env | grep NODEJS
OPENSHIFT_NODEJS_PATH_ELEMENT=/var/lib/openshift/538f1c205004461655000227//.node_modules/.bin:/opt/rh/nodejs010/root/usr/bin
OPENSHIFT_NODEJS_PORT=8080
OPENSHIFT_NODEJS_LD_LIBRARY_PATH_ELEMENT=/opt/rh/nodejs010/root/usr/lib64
OPENSHIFT_NODEJS_IDENT=redhat:nodejs:0.10:0.0.17
OPENSHIFT_NODEJS_LOG_DIR=/var/lib/openshift/538f1c205004461655000227/app-root/logs/
OPENSHIFT_NODEJS_IP=127.10.37.129
OPENSHIFT_NODEJS_PID_DIR=/var/lib/openshift/538f1c205004461655000227/nodejs//run/
OPENSHIFT_NODEJS_VERSION=0.10
OPENSHIFT_NODEJS_DIR=/var/lib/openshift/538f1c205004461655000227/nodejs/
and here's what I get for env | grep mongo:
OPENSHIFT_ROCKMONGO_DIR=/var/lib/openshift/538f1c205004461655000227/rockmongo/
PHPRC=/var/lib/openshift/538f1c205004461655000227/rockmongo/etc/conf/php.ini
OPENSHIFT_ROCKMONGO_IDENT=redhat:rockmongo:1.1:0.0.12
OPENSHIFT_MONGODB_IDENT=redhat:mongodb:2.4:0.2.11
OPENSHIFT_MONGODB_DB_URL=mongodb://admin:PASSWORD_HERE#127.10.37.130:27017/
OPENSHIFT_MONGODB_DIR=/var/lib/openshift/538f1c205004461655000227/mongodb/
Just in case someone else stumbles upon this problem, here is what I had to do.
I created separate file config/application.js, and there I placed
module.exports = {
port: process.env.OPENSHIFT_NODEJS_PORT,
host: process.env.OPENSHIFT_NODEJS_IP,
environment: 'production'
};
Also I found what was the problem with application not starting. Post-install was failing (bower install did not finish successfully). To fix it, one should add to scripts section of package.json
"postinstall": "export HOME=/var/lib/openshift/[instance-id]/app-root/runtime/repo; ./node_modules/bower/bin/bower install"

How to use nodemon/grunt with .env files?

I am using an .env file to work with foreman, but am trying to configure nodemon to start my server using grunt, because I enjoy how nodemon restarts when files become modified.
I am trying avoid having an .env file for foreman AND having environment variables stored in my ~/.bash_profile for nodemon. Instead, I would like to configure my .env file to work for both cases.
I found some answers here, and the second answer should work for grunt.
My .env file is of JSON format, which should flatten environment variables via concatenation (see here).
When I run the following command $ env $(cat .env) nodemon app.js, I receive the following error: env: {: No such file or directory.
Anyone have an idea of what the problem may be? Cheers.
I'd suggest filing this at http://github.com/remy/nodemon/issues/new - but I'd also say that there's environment config support in nodemon as of 1.0.9 - though I'm not 100% sure it'll solve what you want.
Basically you put a nodemon.json file in your home directory, and have:
{
"env": {
"USER": "remy",
"PORT": "8000",
"ETC": "etc"
}
}
An example of the config can be seen here and a few more details here.
I haven't tried using the nodemon. But I've figured out how to do restart the server using foreman.
Define a key on your Procfile to run your application with node-supervisor
My proc file have a dev key that is like this: dev: node-supervisor -w .,lib/ webserver.js
The -w option is a comma separated list of the folders that you want to watch.

Resources