Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an app on Heroku with Django and NPM

I'm writing a Django app that includes some CoffeeScript in it. To allow for this I'm using django-compressor which compiles the CoffeeScript to JS before the app is launched. django-compressor requires that NPM is installed on the machine to compile the CoffeeScript.

Now I want to deploy this app on Heroku. I can't put npm in my requirements.txt so I am wondering how I can get npm on the Heroku server?

like image 595
Alexis Avatar asked Feb 21 '12 16:02

Alexis


People also ask

How do you run NPM install on Heroku?

Run the npm install command in your local app directory to install the dependencies that you declared in your package. json file. Start your app locally using the heroku local command, which is installed as part of the Heroku CLI. Your app should now be running on http://localhost:5000/.

Can you build an app in Heroku?

From your browser, navigate to the Heroku dashboard, https://id.heroku.com. Click New. Select Create new app.

Can I deploy frontend and backend on Heroku?

Each process has its own port in dev, but deploying on Heroku uses just one total. Put the working frontend in a subdirectory of root (such as /frontend ). Put the working backend in a subdirectory of root (such as /api -- the blogpost assumes the backend remains in the root directory -- either way is fine).


2 Answers

If you want to avoid maintaining a custom buildpack, you can use the multi buildpack.

Using the multi buildpack is super simple:

  1. Run heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
  2. Create a .buildpacks file in the root of your repository with two lines: https://github.com/heroku/heroku-buildpack-nodejs.git
    https://github.com/heroku/heroku-buildpack-python.git
  3. Create a package.json file with your npm dependencies.
  4. Run npm install
like image 51
yndolok Avatar answered Oct 18 '22 05:10

yndolok


Note: The multi buildpack is a much nicer way to accomplish this these days :)


I've created a fork of the official Python heroku buildpack that allows an optional npm_requirements.txt for installing such dependencies.

I am now using coffeescript and less-css with django-compressor on heroku :)

https://github.com/jiaaro/heroku-buildpack-django

Edit: To switch to my buildback from the standard buildpack:

  1. use the heroku command line app to set the BUILDPACK_URL environment variable:

    heroku config:add BUILDPACK_URL=git://github.com/jiaaro/heroku-buildpack-django.git 
    
like image 41
Jiaaro Avatar answered Oct 18 '22 05:10

Jiaaro