For unit testing purposes I want to trigger a fake http request in expressjs to my routes to test how each respond. Is there an easy way to do this?
Trigger a real request. it will not use any bandwidth since its on the same machine
var options = {
hostname: 'example.com',
path: '/test'
};
http.request(options).end();
Request.js is the most common way to send requests with node.
var request = require('request');
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Print the google web page.
}
})