How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Run a Node.js Application from a Windows .bat File
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > OS > How to Run a Node.js Application from a Windows .bat File
OS

How to Run a Node.js Application from a Windows .bat File

how7o
By how7o
Last updated: May 23, 2026
5 Min Read
Run a Node.js application from a Windows .bat file
SHARE

To run a Node.js application from a Windows .bat file so non-technical users can double-click to start it, create a one- or two-line batch script that cds into your project directory and runs npm start (or node server.js). A desktop shortcut to the .bat gives users a single click to launch.

Contents
  • The simplest .bat
  • Robust version (works from anywhere)
  • Run a specific script or file
  • Create a desktop shortcut
  • For production — install as a Windows service
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on Windows 11 with Node 20 LTS. Originally published 2022-10-13, rewritten and updated 2026-05-17.

The simplest .bat

npm start

Save as start.bat inside your project directory (next to package.json) and double-click. A command prompt opens, runs npm start, and stays open as long as your server runs.

Run Node.js from a .bat — npm start, cd /d %~dp0, pause, NSSM service for production

Robust version (works from anywhere)

@echo off
cd /d "%~dp0"
echo Starting application...
npm start
pause
  • @echo off — hides command echoing (the script lines themselves) so the user sees clean output.
  • cd /d "%~dp0" — changes to the directory the .bat lives in. %~dp0 expands to the script’s path; /d allows switching drives. Now the user can place the .bat anywhere and it still works.
  • pause — keeps the window open after npm exits so the user can read error messages. Drop it for long-running servers that don’t normally exit.

Run a specific script or file

@echo off
cd /d "%~dp0"

REM A specific npm script
npm run dev

REM Or call node directly
node server.js

REM Or with arguments
node server.js --port 4000 --env production

pause

Create a desktop shortcut

  1. Right-click the .bat file → Send to → Desktop (create shortcut).
  2. Right-click the new shortcut → Properties.
  3. Optionally change the icon under Change Icon… to something prettier than the default .bat icon.

The user now has a desktop icon they can double-click to start the app — no command-line knowledge needed.

For production — install as a Windows service

REM Download nssm.exe from https://nssm.cc/ first
nssm install MyNodeApp "C:\Program Files\nodejs\node.exe" "C:\path\to\app\server.js"
nssm set MyNodeApp AppDirectory "C:\path\to\app"
nssm start MyNodeApp

NSSM turns any console process into a Windows service. The app runs in the background, starts on boot, and restarts if it crashes — much better than a .bat for long-running servers in production.

Frequently asked questions

Why does my .bat close immediately after running?

If npm start exits (because there’s no long-running server or it errored out), the command prompt closes the moment the script ends and you don’t see why. Add pause as the last line of the .bat — the window stays open until you press a key, so you can read any error messages.

How do I make sure it works no matter where the user runs it from?

Use %~dp0 at the top — that’s the directory the .bat itself lives in. cd /d %~dp0 changes to that directory before running npm. Without it, double-clicking from a shortcut on the desktop starts in %HOMEDRIVE%%HOMEPATH% and npm start can’t find package.json.

Can I run this hidden so the user doesn’t see the command prompt?

Wrap it with start /B /MIN to start minimized, or use a VBScript wrapper that calls the .bat with no window. For a long-running server, the cleanest option is to install your app as a Windows service with nssm (the Non-Sucking Service Manager) — it runs in the background, starts on boot, and restarts on crash.

Should I distribute the .bat or build an installer?

For a few internal users a .bat + desktop shortcut is fine. For external distribution, consider packaging the app with pkg or nexe (single-binary Node), or wrap it in an Electron-style installer. The .bat approach assumes the user already has Node.js installed and a working npm in PATH.

Related guides

  • How to Install the Latest Node.js on Ubuntu
  • How to cd to a Different Drive in Windows
  • How to Automatically Start Apache and MySQL with XAMPP on Windows

References

Microsoft batch reference: learn.microsoft.com/en-us/windows-server/administration/windows-commands. NSSM (Non-Sucking Service Manager): nssm.cc. Node.js docs: nodejs.org/en/docs.

TAGGED:configurationnodejswindows

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Run a Linux cron job as a non-root user How to Run a Cron Job as a Non-Root User
Next Article Scroll to an element on a web page with jQuery How to Scroll to an Element Using jQuery
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Completely remove MariaDB from a RHEL-family server
Server Management

How to Remove MariaDB Completely from RHEL/CentOS

5 Min Read
Install HandBrake CLI on Linux with Flatpak
Server Management

How to Install HandBrake CLI on Linux (Flatpak)

5 Min Read
Diagnose MySQL 100% CPU usage with PROCESSLIST and INNODB STATUS
Server Management

How to Find What’s Pinning MySQL at 100% CPU

6 Min Read
Switch from LiteSpeed to Apache in WHM/cPanel
Server Management

How to Switch from LiteSpeed to Apache in WHM/cPanel

4 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?