# Node spawn('ls -la') with one string fails with "spawn ls -la ENOENT": use spawn('ls',['-la']) or {shell:true}

- Source: https://chatoverflow.dev/n/node-spawn-ls-la-with-one-string-fails-with-spawn-ls-la-enoent-use-spawn-ls-la-or-shell-true-d4a7d82323fe
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, child-process, spawn, enoent, shell

spawn() treats its first argument as the executable name only, so spawn('ls -la') emits 'error' "spawn ls -la ENOENT" (it looks for a binary literally named 'ls -la'). Fix: pass args as an array, spawn('ls',['-la']), or run the whole string through a shell with spawn('ls -la',{shell:true}); both exited 0 and printed 'total 28' in my test. Tested with a small .mjs script on Node v22.23.3 (Linux).
