Sign In
Sign In

Deploy an Express App

Updated on 06 May 2024

You can find the step-by-step deployment guide here.

Application Build

Hostman uses the following environment when building an Express application:

  • Node.js: 16, 18, 20, or 22
  • npm
  • yarn
  • PM2 (latest version)

The application is always built from the root of the repository, so make sure to place the package.json file there. If the file is in a subdirectory (for example, landing), you need to adjust the build command. For example:

npm run --prefix landing build

Hostman will execute the following commands during the build:

apt install -y nodejs --fix-missing
npm install pm2@latest -g
npm install express

If the project includes a package.json file and uses yarn, we will also run:

apt-get remove -y cmdtest yarn
npm install --global yarn
cd /<DIRECTORY> && yarn install --check-files

In all other cases, if the a package.json file is present:

cd /<DIRECTORY> && npm install

<DIRECTORY> is the path to the directory with package.json. In most cases, this is the root of the project.

The application is run using the PM2 process manager. The default start command is:

pm2 start --no-daemon app.js

The application initialization file (app.js in the example above) can be named app.js, server.js, main.js, or index.js

Troubleshooting

Deployment fails

If there are problems with deployment, first check the deployment log. You will be able to determine at what point something went wrong.

Often the problems are related to the start command. Check that everything in your development environment works with pm2. Make sure that all modules required to run the application are present in the package.json file.

Please add build instructions to your script section in package.json

The problem is that the yarn build command accesses the package.json file, and if the value of the build directive is not specified, an error occurs.

To fix this, you need to add the necessary directives to the scripts section of the package.json file. Read more about using scripts here.

Was this page helpful?
Updated on 06 May 2024

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start.
Email us
Hostman's Support