Forcing Heroku to Treat App as Node.js - node.js

I have a Node.js app which I'm attempting to deploy to Heroku. However, Heroku seems to think that it's a Ruby app, likely because it has a Gemfile (we have a private gem containing some custom scripts and the like, as well as the Heroku gem itself for command-line control). I added Gemfile and Gemfile.lock to the .slugignore (discussed in Heroku's Slug Compiler article), but the app is still detected as a Ruby app.
$ git push heroku master
Total 0 (delta 0), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby app detected
-----> Installing dependencies using Bundler version 1.2.0.pre
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
The bundle fails, because our custom gem is a private repo, and I never get any further. I'm unable to find any way to force Heroku to treat the app as a Node.js app and use the Procfile to start the web app. Does anyone have and idea how I can do this?

Well crap, I must not have looked far enough. This was already asked on Stack Overflow and the answer was to use the custom Node.js build pack, a la:
heroku config:add BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs.git

Related

deploying is failed in heroku with nodejs

Error message
App not compatible with buildpack: https://github.com/Murali5665/tinderclone-1
bash: /tmp/codon/tmp/buildpacks/6808d9bafd7cf888affdcbfa3b24d7368d0a7618/bin/detect: No such file or directory
You have told Heroku to use your app's source code as a buildpack.
A buildpack is a very specific thing:
Buildpacks are responsible for transforming deployed code into a slug, which can then be executed on a dyno. Buildpacks are composed of a set of scripts, and depending on the programming language, the scripts will retrieve dependencies, output generated assets or compiled code, and more. This output is assembled into a slug by the slug compiler.
Heroku’s support for Ruby, Python, Java, Clojure, Node.js, Scala, Go and PHP is implemented via a set of open source buildpacks.
It is uncommon to provide your own custom buildpack, and your source code is not valid as a buildpack.
Clear your configured buildpack:
heroku buildpacks:clear
Then deploy again. Heroku will see your package.json and automatically select the Node.js buildpack.

Nodejs slow at "Preparing build for deployment"

I create a new nodejs app and publish on openshift.
Everything are fast and good.
Then I start to add all Mean dependencies (not dev-dependencies)
and then the push build becomes very slow
remote: Saving away previously installed Node modules remote: Building
git ref 'master', commit 79fb313 remote: Building NodeJS cartridge
remote: Preparing build for deployment
The terminal blocks there for 5 minutes.
I just wonder why it's so slow.
I can ssh to the gear and copy and stop/start my app in less than 30secondes.
There is no log at all nodejs.log !
What is the cardtridge is doing and it takes so much time?
Regards,
Ball

Build and deploy or deploy to build

My application is based on node.js, and uses bower.js and others task runners to compile assets and build the actual assets (minify, concat, inject...).
Since this is my first application that will be running in a scalable enviroment on Heroku, I was wondering how is the process of deploying.
I mean, my current workflow is:
cd myRepo
git commit [blabla...]
git push heroku
And when running it, it runs npm run wich calls geddy and runs the server.
If I build before pushing, there will be files that are kind of redundant, but if I push the unbuilt project, it should build it on the cloud. Is that the main idea?
Thanks
it should build it on the cloud. Is that the main idea?
Correct; checkout the Dev Center for more Nodejs information:
Heroku Dev Center: Getting Started with Nodejs
Specifically here, it lists information on bower:
Heroku Node.js Support: Customizing the Build Process

Speed up deployment on Heroku [duplicate]

This question already has answers here:
Avoid npm refresh after every deployment on Heroku
(4 answers)
Closed 8 years ago.
Heroku is great. But every time I deploy, Heroku seems to like to redownload and rebuild all the packages. With socket.io and mailparser this is taking around 3 minutes.
Is there a way to speed up the deployment process? Is there a way to tell Heroku that it can cache these items? Or can I upload prebuilt node_modules?
It seems like as of today Heroku is finally caching the node_modules folder!
-----> Deleting 6 files matching .slugignore patterns.
-----> Node.js app detected
-----> Requested node range: 0.10.x
-----> Resolved node version: 0.10.22
-----> Downloading and installing node
-----> Restoring node_modules from cache
-----> Installing dependencies
-----> Pruning unused dependencies
-----> Caching node_modules directory for future builds
-----> Cleaning up node-gyp and npm artifacts
Build time is like 3 seconds for me now.
One thing I did to speed up process was to add .slugignore file to the main folder and add all the files and folders I did not want to run the app.
Sample content of .slugignore file:
working
mockups
*.psd
*.pdf
I'm running into the same problem.
Some discussion here about caching the node_modules folder: https://github.com/heroku/heroku-buildpack-nodejs/pull/37
Another idea: https://github.com/heroku/heroku-buildpack-nodejs/issues/25
I'm thinking about a few solutions right now.
Check in node_modules in a separate branch: The core Node.js maintainers actually recommend checking in the node_modules folder into source control (for apps, not libs). I don't like this. A way to get around it though might be to have a separate production branch with a different .gitignore file that doesn't ignore node_modules. When you want to deploy, just do a rebase from your master and node_modules will be checked in. At least this keeps your master branch free from dependencies.
Add a preinstall script to package.json to download compressed dependency zip: You could also add a pre-push git hook to bundle up your dependencies and upload them to S3. This would probably be too slow though.
Modify the heroku-buildpack-nodejs: Integrate the outstanding pull request with node_modules caching:
heroku config:set BUILDPACK_URL=https://github.com/opdemand/buildpack-nodejs.git
I had the same question (see Avoid npm refresh after every deployment on Heroku).
Heroku forces a download/build/etc. sequence because they need to start an app with a 'blank slate': to clean previous undeleted files, when they move your app to another server, when you assign new web dynos, etc.
The issue is clearly with native packages, and recompilation. For all js-only packages, I commit them with my project, and remove them from package.json. It gains a few seconds, but not that much.
I should definitely be possible to pre-compile and commit native modules (I successfully run wkhtml2pdf on Heroku, for instance, with a binary compiled for linux-amd64), if you get access to a Linux box (or VM) with the same configuration - as of today, Linux [...] 2.6.32-350-ec2 #57-Ubuntu SMP [...] x86_64 GNU/Linux.
Though I would not recommend it as a definitive solution, since it is likely to break some day - It does not seem to me that heroku guarantees the platform an app runs onto.
Seems like there has recently been progress at the heroku-buildpack-nodejs.
Once the pull request is merged, you can add
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs
to your heroku environment variables.
For now, David Dollar's forked repository is available at
https://github.com/ddollar/heroku-buildpack-nodejs
With this as your BUILDPACK_URL it should cache the npm modules.
I tried it with node.js 0.10.5a, npm version: 1.3.5 and npm_modules in .gitignore. Tt seems to work fine so far!
Check out this branch of the new Heroku Node.js buildpack, now in beta, which supports node_modules caching between builds:
https://github.com/heroku/heroku-buildpack-nodejs/tree/diet
To use it:
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs#diet -a my-node-app
git commit -am "fakeout" --allow-empty
git push heroku

Changing app from one language to another in heroku

Is it possible to switch a Heroku app on the Cedar stack from one language to another?
In this particular instance I am trying to migrate an app from PHP to NodeJS, which is being detected as a NodeJS app after performing a git push:
-----> Heroku receiving push
-----> Node.js app detected
-----> Fetching Node.js binaries
-----> Vendoring node 0.4.7
-----> Installing dependencies with npm 1.0.94
Dependencies installed
-----> Discovering process types
Procfile declares types -> web
-----> Compiled slug size is 5.0MB
-----> Launching... done, v7
... however it then crashes with:
Error: No such file or directory - node main.js
Trying to run the Node REPL also suggests the binary doesn't exist:
> heroku run node
Running node attached to terminal... up, run.1
sh: node: not found
Is there any way to reinitialise a Cedar stack app, without creating a new instance?
Create a new instance application instance. It is probably not a good idea to try to morph one into the other. DNS will update for you automatically as that's handled by the routing mesh, and you'll be much happier and better off for it.
I (although a slightly different use case) migrated an application from Bamboo to Cedar and the whole process took me less than five minutes. The only downtime was a couple of seconds while I relocated the custom domain setup on the application.
I know it's an old question but I ran into this problem changing my app from PHP to NodeJs. The first time I run the git push heroku master I got an error saying that it couldn't use PHP buildpack.
So I went in my app Settings tab in Heroku dashboard and remove the PHP buildpack from the Buildpacks list.
Finally whe I ran git push heroku master, Heroku auto detected the NodeJS buildpack.

Resources