限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >前端技术 >NodeJs

nodejs学习初体验(1)

分类:NodeJs时间:2019-01-07浏览:2590
// 简单的搭建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/
本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。
0/500
Share your thoughts respectfully.