This is an example of how to set up a Node.js application to deploy on Kinsta’s Application Hosting services from a GitHub repository.

During the deployment process, Kinsta automatically installs dependencies defined in your package.json file.

  1. Log in to GitHub and create a new repository from this template (Use this template > Create a new repository): Kinsta – Hello World – Node.js
  2. In MyKinsta, add an application with the Hello World – Node.js repository. The Start command can be left blank for the web process as Kinsta automatically detects the required command during the first deployment.

The app is available as soon as the build finishes and a Hello World page loads at your application’s URL.

Node.js Hello World page after successful installation.
Node.js Hello World page after successful installation.

Prefer to watch the video version?

Web Server Setup

Port

Kinsta automatically sets the PORT environment variable. You do not need to define it yourself or hard-code it into the application. Use process.env.PORT in your code when referring to the server port.

app.listen(process.env.PORT, () => {
console.log(`Hello World Application is running on port ${process.env.PORT}`)
})

Start Command

When you deploy an application, Kinsta automatically creates a web process with npm start as the Start comand. Make sure you use this command to run your server. If you want to use a different command, you need to modify the web process in MyKinsta.

"scripts": {
"start": "node server.js"
},

Environment Variables

By default, the NODE_ENV environment variable is not set to production for Node.js applications; you must add this environment variable manually.

Deployment Lifecycle

Whenever a deployment is initiated (through creating an application or re-deploying due to an incoming commit), the npm build command is run, followed by the npm start command.