How to deploy a NodeJs server using Laravel Forge – Tutorial

Valerio Barbera
node server logo

Hi, I’m Valerio, a software engineer from Italy and CTO at Inspector.

We recently worked to replace the HTTP handler behind our ingestion endpoint (ingestion.inspector.dev) with a new implementation. We used 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.

By using node.js, we see a 5x performance improvement in managing this large traffic volume. This makes Inspector more reliable and fast.

This article will show you how to deploy a NodeJs server using Forge. Forge is the most popular server management tool in the Laravel community.

It is designed to deploy PHP apps. Still, it’s simple enough to get a node application running. It can because Forge includes a set of services like NGINX and SupervisorD. These can significantly simplify the server configuration.

Laravel Forge NGINX configuration

We need to take advantage of nginx’s excellent built-in 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 our application’s node process on port 3000.

At the bottom of the site details section in your Forge server, you’ll find the “Files” button. Use it to access the site’s NGINX configuration file. The area 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;
}

We’re running a Node.js process bound to a specific port on our VM. So, we need to inform NGINX that all HTTP requests should forward to our Node.js 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 the NodeJs application (e.g. ExpressJs, Fastify, etc.) and return the response it generates to the requesting client.

Supervisor configuration

It would be best to keep your node server working in production. This prevents the process from shutting down due to unexpected errors. For example, the Node.js server process may stop running for various reasons. They could include an exceeded timeout or a script exception.

For this reason, you need to configure a process monitor that can detect when your Node.js process exits and automatically restart it. Supervisor is a process monitor 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 below to start your node server:

node /home/forge/mysite.com/public/server.js

Doing so will ensure your nodejs server keeps running and restarts in case of an 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 strategy is the easiest as you don’t know the PID number here:

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

# install or update npm modules
cd /home/forge/mydomain.com
npm install 

# restart node daemon  
pkill -f 'node /home/forge/mydomain.com/public/server.js'

When the process is killed, the supervisor automatically restarts it loading the last code changes.

Conclusion

Once you are familiar with the process, it will seem very quick and easy, and there are huge benefits. Forge has other features that work with non-Laravel apps.

They include the Schedule tab, which provides an easy way to manage cron jobs. Database helps you use MySQL (or a Postgres) database in your node script.

Autofix your Laravel application for free

Inspector is a Code Execution Monitoring tool specifically designed for software developers. You don’t need to install anything on the infrastructure, just install the Laravel package and you are ready to go.

If you are looking for effective automation, and the ability to automatically receive code change proposals to fix application errors try Inspector for free. Register your account.

Or learn more on the website: https://inspector.dev

Related Posts

Storing LLM Context the Laravel Way: EloquentChatHistory in Neuron AI

I’ve spent the last few weeks working on one of the most important components of Neuron the Chat History. Most solutions treat conversation history in AI Agents forcing you to build everything from scratch. When I saw Laravel developers adopting Neuron AI, I realized they deserved better than that. The current implementation of the ChatHisotry

Managing Human-in-the-Loop With Checkpoints – Neuron Workflow

The integration of human oversight into AI workflows has traditionally been a Python-dominated territory, leaving PHP developers to either compromise on their preferred stack or abandon sophisticated agentic patterns altogether. The new checkpointing feature in Neuron’s Workflow component continues to strengthen the dynamic of bringing production-ready human-in-the-loop capabilities directly to PHP environments. Checkpointing addresses a

Monitor Your PHP Applications Through Your AI Assistant – Inspector MCP server

You push code, hope it works, and discover issues when users complain or error rates spike. Traditional monitoring tools require constant context switching—jumping between your IDE, terminal, dashboard tabs, and documentation. This friction kills productivity and delays problem resolution. Inspector’s new MCP server changes this dynamic by connecting your AI coding assistant directly to your