Open a console/command/terminal window. Type: node -v Expect: v0.10.31 or similar Type: npm -v Expect: 2.1.3 or similar
var request = require('request'); request('http://linksilk.com', function(error,response,body){ console.log('linksilk.com: ', response.statusCode); });
Replace http://linksilk.com with one of your websites/URLs.
Save file.
module.js:340 throw err; ^ Error: Cannot find module 'request'
var options = { followRedirect: false, url: 'http://www.linksilk.com' };
Back to example
Append: console.log('done'); Run: node index.js
Why does "done" before other results?
var request = require('request');
module.exports.run = function(callback) {
request('http://linksilk.com', function(error,response,body){
if(response.statusCode === 200) {
return callback('_ linksilk.com successful');
} else {
return callback('X linksilk.com expected 200 and got ' + response.statusCode);
}
});
};
module.exports.run(function(result){
console.log(result);
});
var assert = require('assert');
var index = require('./index');
describe('test suite', function(){
it('should run all the tests', function(done){
index.run(function(result){
assert.equal(result, '_ linksilk.com successful');
done();
});
});
});
var rewire = require('rewire');
var index = rewire('./index');
index.__set__('request', function(url, callback) {
callback(null, { statusCode: 200 });
});
npm install rewire