nodejs学习笔记之路由
server.js
var http = require("http"); var url = require("url"); function start(route){//route.js 的route方法 //服务实现 function onRequest(request,response){ var pathname = url.parse(request.url.).pathname; route(pathname); // response.writeHead(200,{"Content-Type":"text/plain"}); response.write("只是一个练手罢了"); response.end(); } //创建服务 http.createServer(onRequest).listen(8888);//端口号8888 console.log("服务启动");//后台输出,表示服务启动成功 } exports.start = start; //将start方法暴露出去
========================================
route.js
function route(pathname){ console.log("请求路径是:" + pathname); //后台查看请求路劲 区分请求的地址 } exports.route = route;
========================================
index.js
var server = require("./server"); var router = require("./route"); server.start(router.route);//传递?start的是router的route方法
深入nodejs中流(stream)的理解
nodejs的fs模块并没有提供一个copy的方法,但我们可以很容易的实现一个,比如:varsource=fs.readFileSync('/path/to/source',{encoding:'utf8'});fs.writeFileSync('/path/to/dest'
利用NPM淘宝的node.js镜像加速nvm
NVM加速安装Node.js一般都是用nvm但是安装之后使用体验就不咋地了,由于某些不可变原因,国内网络就不好吐槽了;就连执行一下nvmls-remote都要很久。当
详解从Node.js的child_process模块来学习父子进程之间的通信
child_process模块提供了和popen(3)一样的方式来产生自进程,这个功能主要是通过child_process.spawn函数来提供的:constspawn=require('child_process').spawn;constls=spawn('l
标签:方法,就不,模块,的是,都是