摘要:var multipart = require('connect-multiparty');var fs = require('fs');var multipartMiddleware = multipart();router.get('/uploadTest', function (req, re...
阅读全文
摘要:In this post, we’re going to be creating a sample comments system using Node, Express and Mongoose.Mongoose provides an object oriented interface for using MongoDB in Node.Everything in Mongoose starts with a Schema. Each schema maps to a MongoDB collection and defines the shape of the documents wit
阅读全文
摘要:index.html app.jsvar app=require('http').createServer(handler), io=require('socket.io').listen(app), fs=require('fs'); app.listen(8080); function handler(req,res){ fs.readFile(__dirname+'/index.html',function(err,data){ if (err) { res.writeHead(500...
阅读全文
摘要:form.html server.jsvar http=require("http");var querystring=require("querystring");var util=require("util");var form=require("fs").readFileSync("form.html");http.createServer(function(request,response){ if (request.method==="POST") { var po
阅读全文
摘要:var http=require("http");var url=require("url");var pages=[ {id:"1",route:"",output:"Woohoo!"}, {id:"2",route:"about",output:"A simple routing width node example"}, {id:"3",route:"another page",output
阅读全文
摘要:demo:var events=require('events');var emitter=new events.EventEmitter();emitter.on('someEvent',function(arg1,arg2){ console.log('listener1',arg1,arg2);})emitter.on('someEvent',function(arg1,arg2){ console.log('listener2',arg1,arg2);})emitter.emit('someEven
阅读全文
摘要:demo:var http=require('http');http.createServer(function(req,res){ res.writeHead(200,{'Conten-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');
阅读全文
摘要:demo:var fs=require('fs');fs.readFile('file.txt', 'utf-8',function(err,data){ if(err){ console.error(err) } else { console.log(data); }});console.log('end');
阅读全文