Skip to content

@tj /respondTo.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
meow
var express = require('./')
, app = express();
var users = [];
users.push({ name: 'Tobi' });
users.push({ name: 'Loki' });
users.push({ name: 'Jane' });
app.get('/', function(req, res){
res.respondTo({
'text/html': function(){
res.send('<ul>' + users.map(function(user){
return '<li>' + user.name + '</li>';
}).join('') + '</ul>');
},
'text/plain': function(){
res.send(users.map(function(user){
return ' - ' + user.name + '\n';
}).join(''));
},
'application/json': function(){
res.json(users);
}
})
});
app.listen(3000);
console.log('listening on port 3000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.