Getting Started with Node Applications

The Node agent is the dynoscale-node package. It requires Node.js 18 or newer. The dynoscale-node repository has the Express example, a node:http example, and the rest of the agent setup.

Install Addon

If you are comfortable with the heroku CLI run heroku addons:create dscale. The add-on sets DYNOSCALE_URL. Next, run heroku addons:open dscale to launch your Dynoscale Dashboard.

Alternatively, you can navigate to the Resource tab of your Heroku application. Scroll down to the Addon section and type dynoscale. Select your desired plan type and click on the "Submit Order Form" button. Web and worker dynos have to be Standard or Performance dynos for autoscaling to take effect.

Install the Agent Package

In your development environment run npm install dynoscale-node. Mount the middleware first, before your routes. The agent reports from the dyno whose name ends in .1, normally web.1.

const express = require("express");
const dynoscale = require("dynoscale-node");

const app = express();
app.use(dynoscale());

app.get("/", (req, res) => {
  res.send("Hello from Express, scaled by Dynoscale!");
});

app.listen(process.env.PORT || 3000);
The same call works on Connect. With the node:http module, pass the request through dynoscale() and call your handler from next. Finally, deploy your application to Heroku. Once fully deployed, make an http/https request to your web server to start the measurement process.

Confirm the install with heroku run node -e "console.log(require('dynoscale-node').VERSION)".

BullMQ workers

Install BullMQ in the app with npm install bullmq. The package peer dependency is BullMQ 5 or newer. The adapter turns on when it can load bullmq and finds a Redis URL. Name the queues with a config var, or pass them to the middleware:

heroku config:set DYNOSCALE_BULLMQ_QUEUES=mail,pdf

app.use(dynoscale({
  bullmq: {
    queues: ["mail", "pdf"],
    connection: process.env.REDIS_URL,
  },
}));

With no names configured, the agent scans Redis for BullMQ queues. It checks REDIS_URL, REDIS_TLS_URL, and the Redis Cloud, Redis To Go, OpenRedis, and RedisGreen URL variables. DYNOSCALE_REDIS_URL overrides that search. Set bullmq.prefix when the queues do not use the default bull prefix. Latency is the age of the oldest waiting job. Delayed jobs are not part of that wait list.

Was this page helpful?

0 people found this page helpful so far!