How to deploy a NodeJs server using Laravel Forge – Tutorial

Valerio Barbera

Hi, I’m Valerio, software engineer from Italy, and C.T.O. at Inspector.

We recently worked to replace the http handler behind our ingestion endpoint ( with a new implementation in pure NodeJs. This endpoint receives monitoring data sent from all applications connected to our Code Execution Monitoring engine, and it treats more than 5 million http requests per day.

Using Nodejs we are seeing a 5x performance improvement in managing this large volume of traffic making Inspector more reliable and fast.

In this article I’ll show you how to deploy a NodeJs server using Forge, the most popular server management tool in the Laravel community.

Forge was primarily designed to deploy PHP apps, but it’s simple enough to get a node application running because it includes a set of services like NGINX and SupervisorD that which can greatly simplify the server configuration.

NGINX configuration

We just need to take advantage of nginx’s excellent built-in proxy capabilities.

Suppose to have a NodeJs server running on port 3000:

// Start web server
http.createServer((req, res) => {

    // Managing the incoming http request

}).listen(3000, () => {
    console.log("Server is listening on port: 3000")

We need to tell nginx that inbound requests should be proxied to the node process running our application on port 3000.

At the bottom of the site details section in your Forge server you’ll find the “Files” button to access the site’s NGINX configuration file. The section that we’re interested in is the “location” block that begins with “/”. For a standard PHP or Laravel site, the default setting of try_files works well.

Here is the default configuration provided by Forge:

location / {
    try_files $uri $uri/ /index.php?$query_string;

In our case, we’re running a Nodejs process that’s bound to a specific port on our VM, so we need to inform NGINX that all http requests should be forwarded to our Nodejs process in the appropriate port.

Replace this section with the script below:

location / {
    proxy_pass http://localhost:3000; # Port number of node http server
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection 'upgrade';
   proxy_set_header Host $host;
   proxy_cache_bypass $http_upgrade;

Nginx will now forward incoming requests to our NodeJs (e.g. ExpressJs, Fastify, etc.) application and return the response it generates to the requesting client.

Supervisor configuration

In production you need to keep your node server working, preventing the process from shutting down due to unexpected errors. The nodejs server process may stop running for a variety of reasons, such as an exceeded timeout or a script execption.

For this reason, you need to configure a process monitor that can detect when your nodejs process exit and automatically restart it. Supervisor is a process monitor commonly used in Linux environments and it’s available by default in the servers provisioned by Forge.

In the Forge panel you can add a nodejs command as a daemon in the “Server > Daemons” menu.

Add the command to start your node server:

node /home/forge/

This will make sure your server keeps running and is automatically restarted in case of error.

Deploy script

Additionally we can use quick deploy in Forge, below is a valid deployment script. It uses “pkill -f” to kill the supervisor process by full command name. This was the easiest I came up with as you don’t know PID number here:

# pull latest code version
cd /home/forge/
git pull origin main 

# install or update npm modules
cd /home/forge/
npm install 

# restart node daemon  
pkill -f 'node /home/forge/'

When the process will be killed the supervisor automatically restart it loading the last code changes.


Once you are familiar with the process it will seem very quick and easy, and there are some huge benefits. Forge also has other features that can be used for non-Laravel apps, such as the Schedule tab, which provides an easy way to manage cron jobs, and Databases if you want to use a MySQL (or Postgres) database in your node script.

I hope this article “How to deploy a NodeJs server using Laravel Forge” is a good starting point for your next Nodejs project. If you are interested in Monitoring your Code Execution in real-time, register your Inspector account for free.

Related Posts

How to configure HTTPS in Laravel Homestead

How to enable HTTPS in Laravel Homestead

Hi, I’m Valerio Barbera, software engineer, founder and CTO at Inspector. In this article I’ll show you how to enable HTTPS for your local applications served by Homestead. I met this need because I am working to implement browser notifications for Inspector using Pusher/Beams. But Beams requires that the application be necessarily served over HTTPS.

Laravel cron scheduling and its secrets

Hi, I’m Valerio Barbera, software engineer, founder and CTO at Inspector. Laravel tasks scheduling is one of the most useful features of the framework.The official documentation clearly explains what it is for: In the past, you may have written a cron configuration entry for each task you needed to schedule on your server. However, this

Laravel validation and custom rules in Inspector

Hi, I’m Valerio Barbera, software engineer, founder and CTO at Inspector. Data validation is one of the fundamental features in any application and it is something developers manipulate almost every day. The value a software provides to users is often a function of the quality of data it is able to manage. Laravel ships with

How to build scalable applications

Read the best news, tips and other direct in your inbox