npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

heroku-deployer

v1.0.3

Published

Node.js module and CLI that makes deploying to Heroku a child's play

Downloads

5

Readme

heroku-deployer

Node module and CLI package to easily deploy an Heroku application and/or update its configuration.

The main advantage of using this package is the ability to deploy an app using only a JSON configuration file.

Install

$ npm i heroku-deployer

CLI

$ heroku-deployer <path-to-env.json> -a <my-heroku-app> -t <my-heroku-token> -d <path-to-source-code>

Full list of options:

Usage: heroku-deployer [options] <configFile?>

  Options:

    -h, --help               output usage information
    -V, --version            output the version number
    -a, --app [string]       Heroku application name
    -t, --token [string]     Heroku API token
    -d, --src-dir [dirname]  Path to the application source code
    --app-only               Deploy application without updating its configuration
    --config-only            Update the application configuration without deploying code

Node module

Use

const Deployer = require('heroku-deployer');
const deployer = new Deployer({
    // ...
});

deployer.deploy()
.then(() => {
    console.log('App has been successfully deployed to Heroku with updated configuration!');
});

Parameters

All parameters to use heroku-deployer can be passed directly in the opts hash when creating a new instance and/or using a JSON configuration file. However, parameters passed directly in the opts hash will take precedence over the values in the configuration file.

const opts = {
    // -- Required opts
    // -- Must be passed directly or exist in configFile
    // Heroku App name
    app: 'my-heroku-app',
    // Heroku API token
    token: 'my-heroku-token',
    // Path to source code to bundle and deploy
    srcDir: '<path-to-source-code>',

    // -- Optional opts with default values
    // Configuration file to use for values instead of passing each parameter
    configFile: '<path-to-config-file.json>',
    // Version to use for Heroku build
    // Not used if using the <useGitVersion> parameter
    buildVersion: null,
    // List of buildpacks to update passed as Strings
    // Example: buildpacks: []
    buildpacks: [],
    // Heroku environment variables hash
    // All missing previously set keys will be deleted by the config update
    env: {},
    // Force deployment even though Heroku status is not all green
    force: false,
    // Used globs to create the app bundle
    // If passed empty, no files will be copied
    srcGlobs: [ '**/*' ],
    // Use srcDir last commit as build version
    useGitVersion: true
};

Those two code snippets will then do exactly the same:

const Deployer = require('heroku-deployer');
const deployer = new Deployer({
    app: 'my-heroku-app',
    token: 'my-heroku-token',
    srcDir: '<path-to-source-code>',
    buildVersion: 'v1',
    buildpacks: [
        'https://github.com/heroku/heroku-buildpack-nodejs.git',
        'https://github.com/heroku/heroku-buildpack-nginx.git'
    ],
    env: {
        FOO: 'BAR'
    }
});

deployer.deploy()
.then(() => {});
// env.json
// {
//     "app": "my-heroku-app",
//     "token": "my-heroku-token",
//     "srcDir": "<path-to-source-code>",
//     "buildVersion": "v1",
//     "buildpacks": [
//         "https://github.com/heroku/heroku-buildpack-nodejs.git",
//         "https://github.com/heroku/heroku-buildpack-nginx.git"
//     ],
//     "env": {
//         "FOO": "BAR"
//     }
// }

const Deployer = require('heroku-deployer');
const deployer = new Deployer({
    configFile: './env.json'
});

deployer.deploy()
.then(() => {});

Simple API

All instance functions return bluebird Promises.

deployer.deploy()

Deploy the whole application to Heroku and updates its configuration using the env parameter. Be sure to always pass your whole environment variables list since all missing values will be unset on Heroku.

deployer.deployApp()

Deploy the whole application to Heroku without updating its configuration.

deployer.deployConfig()

Update the application's configuration using the env parameter without deploying the app. Be sure to always pass your whole environment variables list since all missing values will be unset on Heroku.

Advanced API

deployer.checkHerokuStatus()

Logs current status and fail if Heroky status is not all green. Used to check heroku status before deploying.

deployer.packBundle()

Copies files from srcDir to ${srcDir}/tmp/app-bundle directory using srcGlobs options then creates a bundle.tgz file in ${srcDir}/tmp. The copied files in ${srcDir}/tmp/app-bundle are not deleted after this call.

deployer.clearBundleDir()

Deletes both the ${srcDir}/tmp/app-bundle directory and its associated ${srcDir}/tmp/bundle.tgz file.

deployer.updateBuildpacks()

Updates the list of used buildpacks for the Heroku application using the list provided as parameter.

deployer.createSource()

Create a new source endpoint for the app on Heroku and sets deployer.sourceBlob to the sub source_blob object returned by the Heroku API. See https://devcenter.heroku.com/articles/platform-api-reference#source for more details.

deployer.uploadSource()

Upload the generated ${srcDir}/tmp/bundle.tgz file to the Heroku source PUT URL. Calls to deployer.packBundle() and deployer.createSource() are required before this action.

deployer.getGitVersion()

Use srcDir last Git commit SHA as the Heroku build version. If the buildVersion parameter was passed, this overrides its value.

deployer.createHerokuBuild()

Triggers a new Heroku build using the uploaded source file and the buildVersion parameter if any, or the last Git SHA if deployer.getGitVersion() has been called. The Heroku build logs are then streamed to the console.

deployer.checkBuildStatus()

Check the status of the build triggered by deployer.createHerokuBuild(). Fails if the build was not successful.