If you are already familiar with the Cloud Platform user interface, getting started with a Node.js application is similar to the other applications you have already created in Cloud Platform.
For your reference, here is how Node.js applications and environments are managed, and how you develop your code in them, which may be slightly different than your previously created applications and environments.
Many of the basic application management functions are the same for Cloud Platform-hosted Drupal applications. These functions include:
For a full explanation of each of these functions, see Managing applications with the Acquia Cloud Platform interface.
The Cloud Platform implementation of Node.js uses separate environments to help you maintain a clear and orderly workflow as you develop, test, and publish your applications. An application is deployed on each of its environments, but each environment may be in a different state—possibly with a build artifact deployed. Each environment has a URL at which its application can be accessed, but only the production environment’s URL is designed to be visible to the application’s users (website visitors).
Acquia Node.js applications start with one production (Prod) environment, and one development (Dev) environments. See Resources and limitations for Node.js environments for infrastructure details.
The Overview page for an environment displays the Node.js version installed on an environment. To check the version installed on an environment, complete the following steps:
The Cloud Platform user interface displays the Node.js version at the bottom of the Information section as shown in the following example:
Select your application and environment.
Click the Configure icon. Cloud Platform will display the Configuration panel.
In the Configuration panel, select the Node version you want to use for the environment:
Click Save.
Development with Node.js on Cloud Platform requires you create pipelines for your code.
Based on the normal pipelines workflow, after connecting your application to a repository, you must create your build definition file.
The Cloud Platform uses the conventional npm start
command to start your
Node.js application. Ensure that you have a snippet similar to the following in
your application’s package.json
file:
"scripts": {
"start": "node index.js"
}
Enclose your application in error-handling code which captures error
information through console.log()
or console.error()
for log and error
message display in Log Streaming.
Node.js applications on Cloud Platform have a docroot
directory. This
directory isn’t used by Node.js applications, and can be safely added to your
.gitignore
file.
For a detailed tutorial about local Drupal and Node.js setup, see Node.js with Decoupled Drupal on Cloud Platform
The pipelines client for Cloud Platform includes commands that are specific to Node.js applications and commands available for your YAML file. For a listing of commands in the CLI client, see Using the Cloud Platform pipelines client.
Here is an example script for building a pipelines artifact with your Node.js application:
# For more acquia-pipelines.yaml pipelines examples, see
# https://docs.acquia.com/pipelines/yaml/examples/
version: 1.0.0
variables:
global:
events:
build:
steps:
- build:
script:
- nvm install 10
- nvm use 10
- npm install --production
- upload-artifact:
script:
- pipelines-artifact start
- pipelines-artifact upload $SOURCE_DIR
fail-on-build:
steps:
- fail:
script:
- pipelines-artifact fail
For other example scripts for pipelines, see Example pipelines build definition files.