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