How7oHow7o
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Run a Node.js Application from a Windows .bat File
Share
Notification Show More
Font ResizerAa
How7oHow7o
Font ResizerAa
  • Tools
  • Prank Screens
  • Learn
  • Blog
Search
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • 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.

You Might Also Like

fail2ban shield blocking incoming brute-force probes, log file feeding the scanner
Server Management

How to Install fail2ban on Ubuntu (SSH, nginx, and WordPress Filters)

10 Min Read
Reset the LiteSpeed WebAdmin Console password
Server Management

How to Reset the LiteSpeed WebAdmin Console Password

4 Min Read
Fix missing PHP Authorization header on Apache and cPanel
Server Management

How to Fix Missing Authorization Header in PHP Requests

5 Min Read
Laravel run without .env file — env() fallback in config/app.php
Web Development

How to Run a Laravel Project Without a .env File

8 Min Read
How7oHow7o

Free browser-based tools, prank screens, and step-by-step tech tutorials. No signup, nothing uploaded.

  • Private by design — your files never leave your device
  • Instant — no signup, no install, no waiting
  • Always free — no trials, no watermarks, no paywalls

Tools

  • PDF Editor
  • Image Upscaler
  • JPEG Compressor
  • Password Generator
  • QR Code Generator
  • Video Trimmer
  • See all tools →

Pranks

  • Cracked Screen Prank
  • Fake Blue Screen (BSOD)
  • Fake Disk Format
  • Fake Low Battery
  • Fake Nintendo Switch Update Screen
  • Fake PlayStation Update Screen
  • 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?