Skip to content

Instantly share code, notes, and snippets.

@Choonster
Last active November 14, 2021 03:10
Show Gist options
  • Save Choonster/fae5a92182c8ac58e5d61e96eb0ab081 to your computer and use it in GitHub Desktop.
Save Choonster/fae5a92182c8ac58e5d61e96eb0ab081 to your computer and use it in GitHub Desktop.

Revisions

  1. Choonster revised this gist Dec 20, 2016. 1 changed file with 0 additions and 93 deletions.
    93 changes: 0 additions & 93 deletions DebuggingNodeJSHerokuApps.md
    Original file line number Diff line number Diff line change
    @@ -5,14 +5,6 @@
    Heroku only allows each dyno to send and receive external network traffic on a single port, which means you can't simply
    run `node --debug server.js` and attach your debugger to `your-app.herokuapp.com:5858`.

    To work around this, you can use [ngrok](https://ngrok.com/) and [Heroku ngrok Buildpack](https://github.com/jkutner/heroku-buildpack-ngrok) to tunnel to the debugger's port and access it externally.
    # Debugging Node.js web applications running on Heroku using ngrok

    ## Introduction

    Heroku only allows each dyno to send and receive external network traffic on a single port, which means you can't simply
    run `node --debug server.js` and attach your debugger to `your-app.herokuapp.com:5858`.

    To work around this, you can use [ngrok](https://ngrok.com/) and
    [Heroku ngrok Buildpack](https://github.com/jkutner/heroku-buildpack-ngrok) to tunnel to the debugger's port and access
    it externally.
    @@ -107,89 +99,4 @@ If you're using Node.js Tools for Visual Studio, follow

    ### Step 3: Debug!

    Debug your application as normal.
    This guide assumes your application has already been set up. If it hasn't, read [Heroku's Node.js Documentaion](https://devcenter.heroku.com/categories/nodejs) to get started.

    ## Setup

    ### Step 1: Add Heroku ngrok Buildpack

    Add the Heroku ngrok Buildpack to your application by following [the author's instructions](https://github.com/jkutner/heroku-buildpack-ngrok#setup).

    Make sure to set the `AUX_PORT` config value to the local port you want the debugger to run on and `NGROK_COMMAND` to `tcp`.

    You can also set `NGROK_OPTS` to pass additional options to ngrok.

    ### Step 2: Create the start script

    Create a Bash script that will start your application in debug or release mode as appropriate.
    Make sure your script is marked as executable, this can be done using `chmod +x start.sh` on Unix-like OSs or `git add --chmod=+x -- start.sh` on Windows.

    For debug mode, prefix the command with `with_ngrok` and add the `--debug` argument to `node`.


    For example:
    ```bash
    #!/bin/bash

    if [ "$ENABLE_DEBUG" == "true" ]; then
    echo "Starting with debugger on port $AUX_PORT"
    exec with_ngrok node --debug=$AUX_PORT server.js
    else
    echo "Starting without debugger"
    exec node server.js
    fi
    ```

    This allows you to start or stop debugging your application by changing the `ENABLE_DEBUGGING` config value to `true` or `false` with the `heroku config:set` command.

    ### Step 3: Use the start script

    In your **Procfile** or **package.json**, run the start script to start the application.

    An example **Procfile**:
    ```yaml
    web: ./start.sh
    worker: start-worker-process
    ```
    <br>
    An example **package.json**:
    ```json
    {
    "name": "my-application",
    "author": "Me",

    ...

    "scripts": {
    "start": "./start.sh"
    },
    "engines": {
    "node": "0.12.x",
    "npm": "3.1.x"
    }
    }
    ```

    <br>

    ## Debugging

    ### Step 1: Find your ngrok URL

    If you're not using a reserved domain or TCP address, you'll need to use the [ngrok Dashboard](https://dashboard.ngrok.com/status) to find the URL of your application's TCP tunnel.
    This will be something like `tcp://0.tcp.ngrok.io:18082`.

    Once you have your ngrok URL, you can attach your debugger to it.

    ### Step 2: Attach your debugger

    Attach your debugger to the ngrok URL by following its documentation.

    If you're using Node.js Tools for Visual Studio, follow [these instructions](https://github.com/Microsoft/nodejstools/wiki/Advanced-Debugging#attaching-the-ntvs-debugger).

    ### Step 3: Debug!

    Debug your application as normal.
  2. Choonster revised this gist Dec 20, 2016. 1 changed file with 101 additions and 0 deletions.
    101 changes: 101 additions & 0 deletions DebuggingNodeJSHerokuApps.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,108 @@ Heroku only allows each dyno to send and receive external network traffic on a s
    run `node --debug server.js` and attach your debugger to `your-app.herokuapp.com:5858`.

    To work around this, you can use [ngrok](https://ngrok.com/) and [Heroku ngrok Buildpack](https://github.com/jkutner/heroku-buildpack-ngrok) to tunnel to the debugger's port and access it externally.
    # Debugging Node.js web applications running on Heroku using ngrok

    ## Introduction

    Heroku only allows each dyno to send and receive external network traffic on a single port, which means you can't simply
    run `node --debug server.js` and attach your debugger to `your-app.herokuapp.com:5858`.

    To work around this, you can use [ngrok](https://ngrok.com/) and
    [Heroku ngrok Buildpack](https://github.com/jkutner/heroku-buildpack-ngrok) to tunnel to the debugger's port and access
    it externally.

    This guide assumes your application has already been set up. If it hasn't, read
    [Heroku's Node.js Documentaion](https://devcenter.heroku.com/categories/nodejs) to get started.

    ## Setup

    ### Step 1: Add Heroku ngrok Buildpack

    Add the Heroku ngrok Buildpack to your application by following
    [the author's instructions](https://github.com/jkutner/heroku-buildpack-ngrok#setup).

    Make sure to set the `AUX_PORT` config value to the local port you want the debugger to run on and `NGROK_COMMAND` to
    `tcp`.

    You can also set `NGROK_OPTS` to pass additional options to ngrok.

    ### Step 2: Create the start script

    Create a Bash script that will start your application in debug or release mode as appropriate.
    Make sure your script is marked as executable, this can be done using `chmod +x start.sh` on Unix-like OSs or
    `git add --chmod=+x -- start.sh` on Windows.

    For debug mode, prefix the command with `with_ngrok` and add the `--debug` argument to `node`.

    For example:
    ```bash
    #!/bin/bash

    if [ "$ENABLE_DEBUG" == "true" ]; then
    echo "Starting with debugger on port $AUX_PORT"
    exec with_ngrok node --debug=$AUX_PORT server.js
    else
    echo "Starting without debugger"
    exec node server.js
    fi
    ```

    This allows you to start or stop debugging your application by changing the `ENABLE_DEBUGGING` config value to `true`
    or `false` with the `heroku config:set` command.

    ### Step 3: Use the start script

    In your **Procfile** or **package.json**, run the start script to start the application.

    An example **Procfile**:
    ```yaml
    web: ./start.sh
    worker: start-worker-process
    ```
    <br>
    An example **package.json**:
    ```json
    {
    "name": "my-application",
    "author": "Me",

    ...

    "scripts": {
    "start": "./start.sh"
    },
    "engines": {
    "node": "0.12.x",
    "npm": "3.1.x"
    }
    }
    ```

    <br>

    ## Debugging

    ### Step 1: Find your ngrok URL

    If you're not using a reserved domain or TCP address, you'll need to use the
    [ngrok Dashboard](https://dashboard.ngrok.com/status) to find the URL of your application's TCP tunnel.
    This will be something like `tcp://0.tcp.ngrok.io:18082`.

    Once you have your ngrok URL, you can attach your debugger to it.

    ### Step 2: Attach your debugger

    Attach your debugger to the ngrok URL by following its documentation.

    If you're using Node.js Tools for Visual Studio, follow
    [these instructions](https://github.com/Microsoft/nodejstools/wiki/Advanced-Debugging#attaching-the-ntvs-debugger).

    ### Step 3: Debug!

    Debug your application as normal.
    This guide assumes your application has already been set up. If it hasn't, read [Heroku's Node.js Documentaion](https://devcenter.heroku.com/categories/nodejs) to get started.

    ## Setup
  3. Choonster created this gist Dec 20, 2016.
    94 changes: 94 additions & 0 deletions DebuggingNodeJSHerokuApps.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,94 @@
    # Debugging Node.js web applications running on Heroku using ngrok

    ## Introduction

    Heroku only allows each dyno to send and receive external network traffic on a single port, which means you can't simply
    run `node --debug server.js` and attach your debugger to `your-app.herokuapp.com:5858`.

    To work around this, you can use [ngrok](https://ngrok.com/) and [Heroku ngrok Buildpack](https://github.com/jkutner/heroku-buildpack-ngrok) to tunnel to the debugger's port and access it externally.

    This guide assumes your application has already been set up. If it hasn't, read [Heroku's Node.js Documentaion](https://devcenter.heroku.com/categories/nodejs) to get started.

    ## Setup

    ### Step 1: Add Heroku ngrok Buildpack

    Add the Heroku ngrok Buildpack to your application by following [the author's instructions](https://github.com/jkutner/heroku-buildpack-ngrok#setup).

    Make sure to set the `AUX_PORT` config value to the local port you want the debugger to run on and `NGROK_COMMAND` to `tcp`.

    You can also set `NGROK_OPTS` to pass additional options to ngrok.

    ### Step 2: Create the start script

    Create a Bash script that will start your application in debug or release mode as appropriate.
    Make sure your script is marked as executable, this can be done using `chmod +x start.sh` on Unix-like OSs or `git add --chmod=+x -- start.sh` on Windows.

    For debug mode, prefix the command with `with_ngrok` and add the `--debug` argument to `node`.


    For example:
    ```bash
    #!/bin/bash

    if [ "$ENABLE_DEBUG" == "true" ]; then
    echo "Starting with debugger on port $AUX_PORT"
    exec with_ngrok node --debug=$AUX_PORT server.js
    else
    echo "Starting without debugger"
    exec node server.js
    fi
    ```

    This allows you to start or stop debugging your application by changing the `ENABLE_DEBUGGING` config value to `true` or `false` with the `heroku config:set` command.

    ### Step 3: Use the start script

    In your **Procfile** or **package.json**, run the start script to start the application.

    An example **Procfile**:
    ```yaml
    web: ./start.sh
    worker: start-worker-process
    ```
    <br>
    An example **package.json**:
    ```json
    {
    "name": "my-application",
    "author": "Me",

    ...

    "scripts": {
    "start": "./start.sh"
    },
    "engines": {
    "node": "0.12.x",
    "npm": "3.1.x"
    }
    }
    ```

    <br>

    ## Debugging

    ### Step 1: Find your ngrok URL

    If you're not using a reserved domain or TCP address, you'll need to use the [ngrok Dashboard](https://dashboard.ngrok.com/status) to find the URL of your application's TCP tunnel.
    This will be something like `tcp://0.tcp.ngrok.io:18082`.

    Once you have your ngrok URL, you can attach your debugger to it.

    ### Step 2: Attach your debugger

    Attach your debugger to the ngrok URL by following its documentation.

    If you're using Node.js Tools for Visual Studio, follow [these instructions](https://github.com/Microsoft/nodejstools/wiki/Advanced-Debugging#attaching-the-ntvs-debugger).

    ### Step 3: Debug!

    Debug your application as normal.