NodeJsnodejs学习初体验(1)// 简单的搭建web服务器 var http = require('http'); var server = http.createServer(function(req,res){ res.writeHead(200,{'Content-Type':'text/plain'}); res.end('Hello,world'); }) server.lis作者王明昌发布时间2019-01-07复制// 简单的搭建web服务器 var http = require('http'); var server = http.createServer(function(req,res){ res.writeHead(200,{'Content-Type':'text/plain'}); res.end('Hello,world'); }) server.listen(1337,'127.0.0.1');//监听1337端口,监听到之后执行回调函数 console.log('Server run at http://127.0.0.1:1337'); //命令行到该目录,执行该命令 //node server.js //也可以使用浏览器打开 http://127.0.0.1:1337 // // // 简单函数使用 // 1.浏览器命令 // var a=1; var b=3; var add = function(a,b){return a+b}; console.log(add(a,b)) // 2.命令行 // var a=1; var b=3; var add = function(a,b){return a+b;}; add(a,b); //浏览器命令与命令行 全局变量有所不同 //1.浏览器命令 window //2.命令行 process 测试性能 ab -n1000 -c10 http://localhost:1337/ ab -n1000 -c10 https://www.imooc.com/
2019-01-07nodejs学习初体验(3)api//url网址解析 // url.parse 将网址解析成对象 > url.parse('https://www.imooc.com/video/6710') > url.parse('https:/
2019-01-07nodejs学习初体验(4)小爬虫var http = require('http') var url = 'http://www.imooc.com/learn/348' var cheerio = require('cheerio
2019-01-07nodejs学习初体验(2)模块与包管理工具// 模块与包管理工具 npm install 模块的流程 1. 创建模块 test.js 2. 导出模块 (两种) exports.add = function(){} function add()