Run WScript scripts with nodewscript
masterIf you install winax globally (npm install -g winax), you get access to the nodewscript command. This allows you to run legacy JScript files designed for the Windows Scripting Host (WSH) within a Node.js runtime, enabling the use of npm modules alongside WScript features.
Usage:
nodewscript [options] <Filename.js>Key Differences & Limitations:
- Execution Model: Node.js is non-blocking/async, while WScript is linear. Node.js execution completes when the last statement is done AND all pending promises/callbacks are resolved.
- Implicit Properties: Unlike MS JScript, V8 (Node.js) does not support dynamic property checks on objects that aren't defined in
ITypeInfo. Anif (a.Prop)check might fail even ifa.Propisnullorfalseif it's not explicitly marked as a property. - Function Setters: The JScript syntax
object("key") = "value"for setters will throw a syntax error in V8. You must use standard assignmentobject.key = "value". - Bitness:
nodewscriptuses the same bitness as your installed Node.js version. If your scripts require 32-bit COM objects, use a 32-bit Node.js installation.