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
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026

You Might Also Like

Disable binary logging in MySQL or MariaDB
Server Management

How to Disable Binary Logging in MySQL or MariaDB

5 Min Read
MySQL 8 create user and grant privileges on Ubuntu
Web Development

How to Create Users and Grant Privileges in MySQL 8 on Ubuntu

8 Min Read
Reduce high memory usage on Windows 11
OS

How to Reduce High Memory Usage on Windows 11

7 Min Read
Run a Linux cron job as a non-root user
Server Management

How to Run a Cron Job as a Non-Root User

5 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?