Last active
August 2, 2016 06:29
-
-
Save KJlmfe/8311946 to your computer and use it in GitHub Desktop.
Node内置核心模块与第三方模块使用举例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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