Skip to content

Instantly share code, notes, and snippets.

@KJlmfe
Last active August 2, 2016 06:29
Show Gist options
  • Save KJlmfe/8311946 to your computer and use it in GitHub Desktop.
Save KJlmfe/8311946 to your computer and use it in GitHub Desktop.
Node内置核心模块与第三方模块使用举例
var http = require('http'); //导入内置模块http
//调用内置模块http提供的createServer的API
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
//--------------------------------------------------------//
var request = require('request'); //导入第三方模块request
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Print the google web page.
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment