Sanitize a string to be safe for use as a file name in Windows and Unix
systems by stripping all control
restricted characters (
// Some string that may be unsafe as a filesystem filename var UNSAFE_FILENAME = "h*ello:/world?\u0000"; // Sanitize the unsafe filename to be safe for use as a filename var sanitize = require("sanitize-filename"), filename = sanitize(UNSAFE_FILENAME); // Create a file using the safe filename require("fs").createWriteStream(filename).end();
Sanitize the input string.
npm install sanitize-filename