Run a Node.js app
You can run a Node.js application, such as an Express or Next.js app, on a website. The web server passes visitors’ requests through to your app.
Before you start
Section titled “Before you start”-
Upload your app’s files to the website with SFTP.
-
Make sure the app listens on address
0.0.0.0and reads its port from the setting you will choose below, often through thePORTenvironment variable. -
Install its dependencies over SSH, for example with
npm installin the app’s folder.
Deploy the app
Section titled “Deploy the app”-
Open the website, select Advanced in its navigation bar, then Node.js, then Deploy app.
-
Choose how the app runs marker 1:
- Automatic (Production) starts the app for you and restarts it if it stops. Use this for a live site.
- Manual (Development) sends traffic to the app but does not start it; you start it yourself over SSH. The form shows the command to set up Node in your SSH session.
-
Choose the Node version marker 2. stable is the current stable release.
-
Enter the Startup command marker 3, such as
npm startornode server.js. -
If the app is not in the website’s home folder, enter its folder in Working directory marker 4.
-
Under HTTP Proxy marker 5, leave the switch on so the website’s primary domain sends visitors to the app:
- Path: leave it empty to send the whole website to the app, or enter a path such as
/appto use the app only there. - Port: the port your app listens on.
- Tick Allow web socket proxy upgrade if your app uses WebSockets.
- Path: leave it empty to send the whole website to the app, or enter a path such as
-
Select Deploy.
The app is listed on the Node.js page, where you can change or remove it.