摘要: 1 //使用express 2 var express = require('express'); 3 var app = express(); 4 app.use(express.static(__dirname + '/public')); 5 app.listen(8080); 1 //使用connect 2 var path = require('path'); 3 var ... 阅读全文
posted @ 2017-05-29 01:58 godghdai 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 1 var pg = require('pg'); 2 var util = require('util'); 3 //var co = require('co'); 4 var ConnectionParameters = require('pg/lib/connection-parameters'); 5 //var http = require('http'); 6... 阅读全文
posted @ 2017-05-29 01:47 godghdai 阅读(683) 评论(0) 推荐(0) 编辑
摘要: 1 //CommonJS模块规范, 2 //每个模块存在着require、exports、module 这3个变量,nodejs对获取的js文件内容进行了头尾包装 3 (function (exports, require, module, __filename, __dirname) { 4 var math = require('math'); 5 export... 阅读全文
posted @ 2017-05-29 01:40 godghdai 阅读(241) 评论(0) 推荐(0) 编辑
摘要: 1 var data = { 2 customers: [{ 3 id: 1, 4 firstname: 'John', 5 lastname: 'Smith', 6 sex: 'male' 7 }, { 8 id: 2, 9 firstname: 'Jessica'... 阅读全文
posted @ 2017-05-29 01:33 godghdai 阅读(956) 评论(0) 推荐(0) 编辑
摘要: 1 function TaskRun(tasks,done) 2 { 3 var task_index=0; 4 done=done||((err)=>{ 5 err&&console.log(err); 6 }); 7 function next() { 8 if(task_index==tasks.leng... 阅读全文
posted @ 2017-05-29 01:28 godghdai 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 1 var getFun=function(value){ 2 return function(callback){ 3 setTimeout(function(){ 4 callback(value); 5 },1000); 6 }; 7 } 8 9 ;+function(gen){ 10 var next=gen(); 11 fu... 阅读全文
posted @ 2017-05-29 01:24 godghdai 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 1 function Promise(fn) 2 { 3 this._resolvefun=null; 4 this._rejectfun=null; 5 this.status="pending"; 6 this.value=""; 7 this.reason=""; 8 var bind=function(ctx,fun){ ... 阅读全文
posted @ 2017-05-29 01:17 godghdai 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 结果 0:before yield 1:before yield 2:before yield 2:after yield 1:after yield 0:after yield 结果 0:before yield 0 1:before yield 2 2:before yield 4 5 2:af 阅读全文
posted @ 2017-05-29 01:07 godghdai 阅读(196) 评论(0) 推荐(0) 编辑