There is response.format method which uses selects certain render method based on the "Accept" header. http://expressjs.com/4x/api.html#res.format
The response could look like this:
res.format({
text: function(){
res.send('hey');
},
html: function(){
res.send('hey');
},
json: function(){
res.send({ message: 'hey' });
}
});