How do I escape a string for a shell command in node? June 11, 2023 by Tarik This is what I use: var escapeShell = function(cmd) { return '"'+cmd.replace(/(["'$`\\])/g,'\\$1')+'"'; };