NodeJS
Generated on 24 Jun 2026 from the NodeJS catalog page
A lightweight platform ideal for building fast, scalable network applications in Javascript. Similar in design to Ruby’s Event Machine or Python’s Twisted, and built on Chrome’s JavaScript runtime, NodeJS is ideal for data-intensive apps that run across distributed devices.
Software Included
| Package | Version | License |
|---|---|---|
| Node.js | 22.x | Custom |
| NPM | 6.14.4 | Artistic License 2.0 |
| NGINX | 1.17.10 | Custom |
| PM2 | 4.4.0 | GNU AGPL v3 |
Creating an App using the Control Panel
Click the Deploy to DigitalOcean button to create a Droplet based on this 1-Click App. If you aren’t logged in, this link will prompt you to log in with your DigitalOcean account.
Creating an App using the API
In addition to creating a Droplet from the NodeJS 1-Click App using the control panel, you can also use the DigitalOcean API. As an example, to create a 4GB NodeJS Droplet in the SFO2 region, you can use the following curl command. You need to either save your API access token to an environment variable or substitute it in the command below.
curl -X POST -H 'Content-Type: application/json' \
-H 'Authorization: Bearer '$TOKEN'' -d \
'{"name":"choose_a_name","region":"sfo2","size":"s-2vcpu-4gb","image":"nodejs-20-04"}' \
"https://api.digitalocean.com/v2/droplets"Getting Started After Deploying NodeJS
Node.js 1-Click
Deploy Node.js on Ubuntu 24.04 with Nginx and PM2. A sample application runs at /var/www/html/hello.js and is served via Nginx on port 80. You can optionally attach a DigitalOcean Managed MongoDB database during deployment.
Getting Started
- Select the Node.js 1-Click from the DigitalOcean Marketplace
- Choose a Droplet size and region
- Optionally select Add a Database to provision a Managed MongoDB database (see below)
- Create the Droplet
After you create a Droplet, navigate to its public IPv4 address in a browser to see the sample application live.
To SSH into the Droplet, you will be prompted for a password. If you created your Droplet with a root user password, enter that password. If you created your Droplet with an SSH key, enter the passphrase associated with your key.
ssh root@your-droplet-ipSFTP access (for uploading files):
- User:
nodejs - Password: stored in
/root/.digitalocean_passwords(NODE_USER_PASSWORD)
Using MongoDB Database-as-a-Service
When creating your Node.js Droplet, you can select Add a Database to provision a DigitalOcean Managed MongoDB cluster at the same time. A managed database can replace a self-hosted one to better secure your data and gives you easy backups, connection pools, and metrics.
What happens when you add a database
When you choose this option during Droplet creation, DigitalOcean:
- Provisions a Managed MongoDB cluster in the same region as your Droplet
- Passes connection credentials to your Droplet at first boot in
/root/.digitalocean_dbaas_credentials - Exposes a
DATABASE_URLenvironment variable containing the full MongoDB connection string
The Managed MongoDB cluster may take up to five minutes after creation before it is ready for connections. The sample Node.js application is not automatically configured to use the managed database — update your application code to connect using DATABASE_URL or the credentials in /root/.digitalocean_dbaas_credentials.
Sample MongoDB connection
Here is a sample Node.js app showing a connection to the MongoDB database:
const { MongoClient } = require('mongodb');
async function main() {
/**
* Connection URI. Use the DATABASE_URL environment variable, or build the
* connection string from /root/.digitalocean_dbaas_credentials.
* See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
*/
const uri = process.env.DATABASE_URL || '<your-mongo-connection-string>';
const client = new MongoClient(uri);
try {
await client.connect();
await listDatabases(client);
} catch (e) {
console.error(e);
} finally {
await client.close();
}
}
async function listDatabases(client) {
const databasesList = await client.db().admin().listDatabases();
console.log('Connected successfully. Databases:');
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
}
main().catch(console.error);Security: Trusted Sources
Your Droplet is not automatically added to the Managed Database’s trusted sources. For better security, add your Droplet’s public IP address to the database cluster’s Trusted Sources in the DigitalOcean control panel:
- Open your database cluster in the control panel
- Go to Settings → Trusted Sources
- Add your Droplet’s public IP address
Modifying database settings later
- Connection string:
DATABASE_URLenvironment variable or/root/.digitalocean_dbaas_credentials - Password rotation: If you change credentials in the control panel, update your application’s MongoDB connection string to match
Deploying Your Own Application
Step 1: Access your Droplet
ssh root@your-droplet-ipStep 2: Modify the sample application
Edit the sample script at /var/www/html/hello.js. The application runs as the nodejs user via PM2, so run PM2 commands as that user:
sudo -u nodejs pm2 restart helloStep 3: Get your code onto the Droplet
Clone your Node.js code onto the Droplet anywhere you like. If you’re not using source control, you can upload files directly using SFTP.
cd /path/to/your/app
npm install
sudo -u nodejs pm2 start <your-file>Map the port your app runs on to an HTTP URL by editing the Nginx config:
nano /etc/nginx/sites-available/defaultEdit the existing entry that exposes the hello app at port 3000 so that it points to your app’s port instead. Then enable the new config:
systemctl restart nginx
sudo -u nodejs pm2 saveRepeat these steps for any other Node.js apps that need to run concurrently — schedule them to run at boot time on whatever internal port you like using PM2, then map that port to an HTTP/HTTPS URL in the Nginx config. Build out the URL directory structure you need by mapping applications to URL paths; that’s the reverse proxy method in a nutshell.
To remove the sample app:
sudo -u nodejs pm2 delete hello
sudo -u nodejs pm2 saveStep 4: Get production-ready
Popular steps before going to production:
- Non-root user: Set up a non-root user for day-to-day use
- Firewall: Review settings with
sudo ufw status. By default, only SSH/SFTP (port 22), HTTP (port 80), and HTTPS (port 443) are open. You can disable the local firewall withsudo ufw disableand use a DigitalOcean Cloud Firewall instead - Domain: Register a custom domain
- Storage: Mount a Volume (up to 16 TB) to expand the filesystem, provision a Managed Database cluster, or use a Space (S3-compatible object storage)
Droplet Summary
- UFW firewall allows SSH (port 22, rate limited), HTTP (port 80), and HTTPS (port 443)
- Sample app:
/var/www/html/hello.json port 3000, proxied by Nginx on port 80 - Application user:
nodejs(password in/root/.digitalocean_passwords) - Managed MongoDB credentials:
/root/.digitalocean_dbaas_credentialsandDATABASE_URL(when Add a Database was selected) - Nginx config:
/etc/nginx/sites-available/default - Setup log:
/var/log/one_click_setup.log