Front End Hosting - Advanced provisions a Node.js application with the following environments:
Development (Dev)
Staging (Stage)
Production (Prod)
New environments are provisioned with the default content page.
To verify that a site is working correctly, visit the default URL of a specific environment:
Configure the package.json
file.
The package.json
file must be located in the root folder of your project that contains the following commands. These are required to host a NodeJS site.
Build command configuration.
Utilize the NodeJS Hosting's build system by setting npm install && npm run build
as your build command, assuring a robust and efficient deployment process.
"scripts": {
...
"build": "npm install && next build",
"start": "next start",
},
It is not required to define the dependencies in the build command if they are already installed in the Git branch.
Configure the start script in your package.json file in order to initiate the production server. Use the command that corresponds to your specific framework.
{
"scripts": {
"build": "npm install",
"start": "node index.js"
},
}
To serve production builds of frameworks like Angular, React, and Vue, we recommend using either serve or http-server. These Node.js packages provide simple and efficient ways to host static files.
Install your preferred package using npm:
$ npm install serve
or
$ npm install http-server
After you build the project (typically into a dist directory), start the production server with the following commands:
serve -s dist
http-server dist
You can also include these commands in the start script of your package.json
for easy deployment.
Ensure that your build output is located in the dist directory (or adjust the path in the commands accordingly).
Autoscaling is vital to enhance the performance of your application and enable it to handle variable workloads. This feature dynamically adjusts the number of active instances of your environment based on its real-time performance metrics. The enablement process revolves around integrating the acquia-autoscaling
javascript into your project that collects the necessary metrics.
To implement autoscaling in your application:
Add the acquia-autoscaling.js
script to the root directory of your project.
The following code snippet shows the content of the script:
// acquia-autoscaling.js
const { collectDefaultMetrics, Registry } = require('prom-client');
// Create a new registry to track default metrics
const register = new Registry();
// Enable the collection of default metrics
collectDefaultMetrics({ register });
// Set up an HTTP server to expose the metrics
const http = require('http');
const server = http.createServer(async (req, res) => {
if (req.url === '/metrics') {
try {
// Respond with metrics in Prometheus format
res.setHeader('Content-Type', register.contentType);
const metrics = await register.metrics();
res.end(metrics);
} catch (err) {
res.writeHead(500);
res.end(err.message);
}
} else {
res.writeHead(404);
res.end('Not Found');
}
});
const monitoringPort = 9100;
server.listen(monitoringPort, () => {
console.log(`Acquia Node.js Monitoring server listening on port ${monitoringPort}`);
});
// Prevent the Node.js process from exiting
process.stdin.resume();
Edit the the package.json
file to add the NODE_OPTIONS='-r ./acquia-autoscaling.js'
string before the original start
command of your application:
If your original start
command is node server.js
, change it to:
"start": "NODE_OPTIONS='-r ./acquia-autoscaling.js' node server.js"
If your original start
command is next start
, change it to:
"start": "NODE_OPTIONS='-r ./acquia-autoscaling.js' next start"
Ensure that you place the string right before the main entry point of your application in the start
script. Otherwise, the autoscaling feature might become inoperative.
Install the prom-client
dependency by running the following NPM command:
npm install prom-client
This command adds the prom-client
package to your application's dependencies.
Ensure that you install the prom-client
package correctly because it is mandatory for the acquia-autoscaling.js
script to work.
Verify the functionality of your application to ensure that metrics are being correctly exposed and autoscaling is operational.
After successful implementation and verification, your application can scale automatically to adapt to usage patterns and sustain optimal performance.
For information about configuring environment variables, visit Creating custom environment variables.
To use the latest environment variable values in your Node.js code, incorporate them during the Node.js build process. Any changes to environment variables will require a redeployment of your Front End Hosting - Advanced site to update both build and runtime environments.
Visit Code workflows with Cloud Platform.
Deployment implicitly triggers the build.
Deploy the branch <new-branch> on the Cloud UI.
For more information, visit Deploying code in the same environment
NodeJS workflows will build the artifact and deploy it on Node JS sites.
In the future, new commits to the new branch trigger its deployment automatically.
For information about viewing your subscription details, visit Viewing subscriptions.
For monitoring instructions, visit Using Stack Metrics to monitor activity on your environments.
As part of the code build/deployment process, multiple commands run in the backend to produce a build artifact and deploy it to an environment. These include:
The total build time is tracked as build minutes.
If this content did not answer your questions, try searching or contacting our support team for further assistance.
Wed Jun 25 2025 07:19:49 GMT+0000 (Coordinated Universal Time)