Skip to content

Instantly share code, notes, and snippets.

@kasajian
Forked from a-sync/embedded_nodejs.bat
Created October 23, 2020 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasajian/1348cef4f23d322c4b7f24471849d2d0 to your computer and use it in GitHub Desktop.
Save kasajian/1348cef4f23d322c4b7f24471849d2d0 to your computer and use it in GitHub Desktop.
A single batch file that downloads a nodejs binary and runs the code embedded in itself. (for windows 7 and above)
if ("0"=="1") /*
@echo off
set args=%*
setlocal ENABLEDELAYEDEXPANSION
if not exist %TEMP%\node.exe (
echo DOWNLOADING RUNTIME...
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://nodejs.org/dist/latest/win-x64/node.exe', '%TEMP%\node.exe')"
echo DOWNLOAD COMPLETE!
)
echo STARTING EMBEDDED APPLICATION
call :NODE_JS
goto :EOF
:NODE_JS
%TEMP%\node.exe "%~f0" %args%
pause
exit /b
*/ {}
// Javascript starts here
function nodeMain(){
console.log('Hello, NodeJS', process.version);
console.log(process.argv.slice(2));
}
nodeMain();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment