If you're in need of an HTML sanitizer, there are plenty of options to choose from. A quick search on NPM will provide you with a list of sanitizers that can be implemented in your nodejs code.
While using the built-in "escape" function may seem like a simple solution, it's important to note that this method alone is not sufficient to prevent XSS attacks.
app.get('/safe/:input',function(req, res) {
var input = escape(req.params.input);
res.send(input)
});
For a more robust approach, consider utilizing a dedicated library designed specifically for HTML sanitization. One such option is the Santizer library, which is a node package based on Google Caja's HTML sanitizer:
var santizer = require('santizer');
...
app.get('/safe/:input',function(req, res) {
var input = santizer.sanitize(req.params.input);
res.send(input)
});