Step 1. Create a service
Step 2. Select the project to deploy
If you are logged in to Hostman with your GitHub, GitLab or Bitbucket account, at this point you will see the repository with your projects, including the private ones.
Choose the project you want to deploy.
To access a different repository, click Connect another repository.
If you didn’t use your Git account credentials to log in, you’ll be able to access the necessary account now, and then select the project.
Step 3. Choose a server
Your Hapi.js application must run on a specific cloud server. Choose the location and configuration of this server. You can upgrade it in the future.
Step 4. Configure the build settings
Next, the App customization window will appear.
First, select NodeJS environment and then Hapi from the list of frameworks.
Then fill in the Start command. For all NodeJS frameworks we use pm2 as the process manager because it's fast, reliable and scalable.
The correct format for the command will be:
pm2 start --no-daemon index.js
Make sure that the name of the main file in the command (index.js) is the same one you're using (for example, server.js).
If necessary, also fill in the Build command. It allows you to customize the build process. You can enter multiple commands separated by &&.
Step 5. Deploy
Click Deploy to start the build process.
Once it starts, you will enter the deployment log. The log contains all the debugging data you'll need. If there are any issues with the code, you will get warning or error messages in the log, specifying the cause of the problem.
Usually it takes some time to install the cloud server during the first deployment.
When the deployment is complete, you will receive an e-mail notification and also see a similar log entry:
Your project is up and ready.
If your application requires a particular Node version, you can specify it in the settings by doing one of the following:
By adding the NODE_VERSION environment variable to your application and setting its value as your preferred version, for example, 12.18.3.
By adding a .node-version file containing the full semantic Node version to the root directory of your project repository.
By using the engines directive in your package.json file which will allow you to set either a specific Node version (for example, 12.18.3) or a range (for example, >=12.18. <13.2).
The deployment fails
If the deployment fails, first of all check the deployment log. You'll see the stage where something went wrong.
The most common issues are with the start command. Check that everything is working properly with pm2 in your development environment. Check that all the modules you need to launch the application are in the package.json file.
Also, we are here to help, so don't hesitate to ask us about the causes via chat.