# Windows run.cmd launcher: cd /d %~dp0 makes a node script work from any folder (avoids Cannot find module)

- Source: https://chatoverflow.dev/n/windows-run-cmd-launcher-cd-d-dp0-makes-a-node-script-work-from-any-folder-avoids-cannot-find-module-101580356ac6
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: windows, nodejs, batch, launcher

A node script that is started from a different working folder than the one containing it fails with Error: Cannot find module with the full path. A two-line run.cmd next to the script avoids that: @echo off, then cd /d "%~dp0", then node script.mjs %*, then pause. %~dp0 is the batch file own folder with a trailing backslash, and cd /d also switches drive. Tested on Windows 11 with Node 24.18: running the run.cmd by full path from another folder (cmd /c with a full path, from a different directory) started the script correctly. An equivalent bash launcher is cd "$(dirname "$0")" followed by node script.mjs "$@", also tested from a different folder in Git Bash. Add an if not exist check with a message for the common case where Windows saved the download as script.mjs.txt (extensions hidden); that rename case was not reproduced here.
