FreeBSD has long been a solid choice for hosting production Node.js applications thanks to its stability, performance tuning options, and ZFS support. Getting Node.js running on FreeBSD 15 takes just a few commands using the pkg package manager, and this guide walks through the full setup from installation to running your app as a system service.
Whether you need to install Node.js on FreeBSD 15, set up npm for package management, or configure a Node.js production service on FreeBSD, this guide covers everything. We’ll install the current LTS release (Node.js 22), verify it works, build a sample Express app, and create a proper rc.d service script so your application starts automatically on boot.
Last verified: March 2026 | Tested on FreeBSD 15.0-RELEASE, Node.js 22.22.0 LTS
Prerequisites
Before starting, make sure you have:
- A FreeBSD 15.0-RELEASE system with root or sudo access
- Network connectivity and a working
pkgpackage manager - A configured hostname and static IP address (see how to set hostname and static IP on FreeBSD)
Update your package repository index before installing anything.
pkg update
If this is a fresh system, you may also want to review FreeBSD package and service management basics to get comfortable with pkg and sysrc.
Install Node.js on FreeBSD 15
FreeBSD’s package repository provides multiple Node.js versions. Check what’s available before choosing one.
pkg search ^node
You should see several major versions listed:
node20-20.20.0 V8 JavaScript for client and server
node22-22.22.0 V8 JavaScript for client and server
node24-24.13.0 V8 JavaScript for client and server
node25-25.3.0 V8 JavaScript for client and server
Node.js 22 is the current LTS (Long Term Support) release, which means it receives security updates and bug fixes until April 2027. For production workloads, always pick the LTS version. Node.js 24 and 25 are current/development releases that may introduce breaking changes.
Install Node.js 22 along with its matching npm package.
pkg install -y node22 npm-node22
The npm package manager is shipped separately on FreeBSD, which is why you need to install npm-node22 explicitly. Without it, you’ll only have the node binary and won’t be able to manage packages.
Verify the Installation
Confirm that both Node.js and npm are working correctly by checking their versions.
node --version
The output should show the installed LTS version:
v22.22.0
Now check npm:
npm --version
You should see npm 11.x confirmed:
11.7.0
Run a quick test to make sure the JavaScript engine works. Create a simple hello world script and execute it.
echo 'console.log("Hello from Node.js on FreeBSD 15!");' > /tmp/hello.js
node /tmp/hello.js
The expected output confirms Node.js is fully operational:
Hello from Node.js on FreeBSD 15!
Install Packages with npm
With npm working, you can pull in any package from the Node.js ecosystem. Here’s a practical example: setting up a basic Express web server.
First, create a project directory and initialize it.
mkdir -p /opt/nodeapp
cd /opt/nodeapp
npm init -y
This creates a package.json with default values. Next, install Express.
cd /opt/nodeapp
npm install express
npm downloads Express and its dependencies into the node_modules directory. Now create a simple web server.
echo 'const express = require("express");
const app = express();
const PORT = 3000;
app.get("/", (req, res) => {
res.send("Node.js is running on FreeBSD 15!");
});
app.listen(PORT, () => {
console.log("Server listening on port " + PORT);
});' | tee /opt/nodeapp/server.js
Start the server to test it.
node /opt/nodeapp/server.js
You should see the server start message:
Server listening on port 3000
Open another terminal and test with curl or visit http://your-server-ip:3000 in a browser.
curl http://localhost:3000
The response confirms Express is serving requests:
Node.js is running on FreeBSD 15!
Press Ctrl+C to stop the server. In the next section, we’ll set it up as a proper system service.
Run Node.js as a Service
Running your app manually is fine for development, but production workloads need a service that starts on boot, restarts on failure, and logs output properly. FreeBSD uses rc.d scripts for this.
First, create a dedicated user to run the application. Never run Node.js as root in production.
pw adduser nodeapp -d /opt/nodeapp -s /usr/sbin/nologin -c "Node.js App User"
chown -R nodeapp:nodeapp /opt/nodeapp
Now create the rc.d service script.
echo '#!/bin/sh
# PROVIDE: nodeapp
# REQUIRE: LOGIN NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="nodeapp"
rcvar="nodeapp_enable"
nodeapp_user="nodeapp"
nodeapp_dir="/opt/nodeapp"
nodeapp_log="/var/log/nodeapp.log"
pidfile="/var/run/${name}.pid"
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -u ${nodeapp_user} -o ${nodeapp_log} /usr/local/bin/node ${nodeapp_dir}/server.js"
load_rc_config $name
: ${nodeapp_enable:=no}
run_rc_command "$1"' | tee /usr/local/etc/rc.d/nodeapp
Make the script executable.
chmod +x /usr/local/etc/rc.d/nodeapp
Enable the service and start it using sysrc, which is FreeBSD’s tool for managing /etc/rc.conf entries.
sysrc nodeapp_enable=YES
service nodeapp start
Verify the service is running by checking the process and testing the endpoint.
service nodeapp status
You should see the daemon process running. Confirm the app responds:
curl http://localhost:3000
The service will now start automatically on every reboot. Check the log file if anything goes wrong.
tail -f /var/log/nodeapp.log
Using nvm as an Alternative
If you need to run multiple Node.js versions on the same machine or want more control over which version you use, nvm (Node Version Manager) is the way to go. This is especially useful for development servers where different projects require different Node.js versions.
Install nvm by cloning the repository.
fetch -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | sh
Reload your shell profile to make the nvm command available.
source ~/.bashrc
If you use sh or csh as your default shell on FreeBSD, add the nvm initialization lines to the appropriate profile file (~/.profile or ~/.cshrc).
List available LTS versions and install one.
nvm ls-remote --lts
Install a specific version with nvm.
nvm install 22
Switch between installed versions at any time.
nvm use 22
Set a default version that persists across shell sessions.
nvm alias default 22
Keep in mind that nvm installs Node.js in your home directory, so it’s best suited for development environments. For production services, the pkg method covered earlier is more appropriate because it integrates with FreeBSD’s system paths and service management.
Conclusion
You now have Node.js 22 LTS running on FreeBSD 15 with npm ready for package management. The Express example and rc.d service script give you a solid foundation for deploying production Node.js applications. For projects that need version flexibility, nvm provides an easy way to switch between Node.js releases without affecting the system-wide installation.