首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

小弟我看过Node.Js了解或入门最好的文章

2012-09-02 
我看过Node.Js了解或入门最好的文章? ? response.writeHead(200, {Content-Type: text/plain})? ? re

我看过Node.Js了解或入门最好的文章

? ? response.writeHead(200, {"Content-Type": "text/plain"});
? ? response.write("Hello World");
? ? response.end();
? }

? http.createServer(onRequest).listen(8888);
? console.log("Server has started.");
}

exports.start = start;

}

exports.route = route;


? ? route(pathname);

? ? response.writeHead(200, {"Content-Type":"text/plain"});
? ? response.write("Hello World");
? ? response.end();
? }

? http.createServer(onRequest).listen(8888);
? console.log("Server has started.");
}

exports.start = start;


? ? route(handle, pathname);

? ? response.writeHead(200, {"Content-Type":"text/plain"});
? ? response.write("Hello World");
? ? response.end();
? }

? http.createServer(onRequest).listen(8888);
? console.log("Server has started.");
}

exports.start = start;

? if (typeof handle[pathname] === 'function') {
? ? handle[pathname]();
? } else {
? ? console.log("No request handler found for " +pathname);
? }
}

exports.route = route;

? if (typeof handle[pathname] === 'function') {
? ? return handle[pathname]();
? } else {
? ? console.log("No request handler found for " +pathname);
? ? return "404 Not found";
? }
}

exports.route = route;


? ? response.writeHead(200, {"Content-Type":"text/plain"});
? ? var content = route(handle, pathname)
? ? response.write(content);
? ? response.end();
? }

? http.createServer(onRequest).listen(8888);
? console.log("Server has started.");
}

exports.start = start;


? ? route(handle, pathname, response);
? }

? http.createServer(onRequest).listen(8888);
? console.log("Server has started.");
}

exports.start = start;

? if (typeof handle[pathname] === 'function') {
? ? handle[pathname](response);
? } else {
? ? console.log("No request handler found for " +pathname);
? ? response.writeHead(404, {"Content-Type":"text/plain"});
? ? response.write("404 Not found");
? ? response.end();
? }
}

exports.route = route;

? ? '</head>'+
? ? '<body>'+
? ? '<form action="/upload"method="post">'+
? ? '<textarea name="text" rows="20"cols="60"></textarea>'+
? ? '<input type="submit" value="Submit text"/>'+
? ? '</form>'+
? ? '</body>'+
? ? '</html>';

? ? response.writeHead(200, {"Content-Type":"text/html"});
? ? response.write(body);
? ? response.end();
}

function upload(response) {
? console.log("Request handler 'upload' was called.");
? response.writeHead(200, {"Content-Type":"text/plain"});
? response.write("Hello Upload");
? response.end();
}

exports.start = start;
exports.upload = upload;


? ? request.setEncoding("utf8");

? ? request.addListener("data", function(postDataChunk) {
? ? ? postData += postDataChunk;
? ? ? console.log("Received POST data chunk '"+
? ? ? postDataChunk + "'.");
? ? });

? ? request.addListener("end", function() {
? ? ? route(handle, pathname, response, postData);
? ? });

? }

? http.createServer(onRequest).listen(8888);
? console.log("Server has started.");
}

exports.start = start;

? if (typeof handle[pathname] === 'function') {
? ? handle[pathname](response, postData);
? } else {
? ? console.log("No request handler found for " +pathname);
? ? response.writeHead(404, {"Content-Type":"text/plain"});
? ? response.write("404 Not found");
? ? response.end();
? }
}

exports.route = route;

? ? '</head>'+
? ? '<body>'+
? ? '<form action="/upload" method="post">'+
? ? '<textarea name="text" rows="20"cols="60"></textarea>'+
? ? '<input type="submit" value="Submit text"/>'+
? ? '</form>'+
? ? '</body>'+
? ? '</html>';

? ? response.writeHead(200, {"Content-Type":"text/html"});
? ? response.write(body);
? ? response.end();
}

function upload(response, postData) {
? console.log("Request handler 'upload' was called.");
? response.writeHead(200, {"Content-Type":"text/plain"});
? response.write("You've sent: " + postData);
? response.end();
}

exports.start = start;
exports.upload = upload;

? ? '</head>'+
? ? '<body>'+
? ? '<form action="/upload"method="post">'+
? ? '<textarea name="text" rows="20"cols="60"></textarea>'+
? ? '<input type="submit" value="Submit text"/>'+
? ? '</form>'+
? ? '</body>'+
? ? '</html>';

? ? response.writeHead(200, {"Content-Type":"text/html"});
? ? response.write(body);
? ? response.end();
}

function upload(response, postData) {
? console.log("Request handler 'upload' was called.");
? response.writeHead(200, {"Content-Type":"text/plain"});
? response.write("You've sent the text: "+
? querystring.parse(postData).text);
? response.end();
}

exports.start = start;
exports.upload = upload;

? ? 'method="post">'+
? ? '<input type="text" name="title"><br>'+
? ? '<input type="file" name="upload"multiple="multiple"><br>'+
? ? '<input type="submit" value="Upload">'+
? ? '</form>'
? );
}).listen(8888);

? ? 'content="text/html; charset=UTF-8" />'+
? ? '</head>'+
? ? '<body>'+
? ? '<form action="/upload"method="post">'+
? ? '<textarea name="text" rows="20" cols="60"></textarea>'+
? ? '<input type="submit" value="Submit text"/>'+
? ? '</form>'+
? ? '</body>'+
? ? '</html>';

? ? response.writeHead(200, {"Content-Type":"text/html"});
? ? response.write(body);
? ? response.end();
}

function upload(response, postData) {
? console.log("Request handler 'upload' was called.");
? response.writeHead(200, {"Content-Type":"text/plain"});
? response.write("You've sent the text: "+
? querystring.parse(postData).text);
? response.end();
}

function show(response, postData) {
? console.log("Request handler 'show' was called.");
? fs.readFile("/tmp/test.png", "binary",function(error, file) {
? ? if(error) {
? ? ? response.writeHead(500, {"Content-Type":"text/plain"});
? ? ? response.write(error + "\n");
? ? ? response.end();
? ? } else {
? ? ? response.writeHead(200, {"Content-Type":"image/png"});
? ? ? response.write(file, "binary");
? ? ? response.end();
? ? }
? });
}

exports.start = start;
exports.upload = upload;
exports.show = show;

? ? 'content="text/html; charset=UTF-8" />'+
? ? '</head>'+
? ? '<body>'+
? ? '<form action="/upload"enctype="multipart/form-data" '+
? ? 'method="post">'+
? ? '<input type="file" name="upload">'+
? ? '<input type="submit" value="Upload file"/>'+
? ? '</form>'+
? ? '</body>'+
? ? '</html>';

? ? response.writeHead(200, {"Content-Type": "text/html"});
? ? response.write(body);
? ? response.end();
}

function upload(response, postData) {
? console.log("Request handler 'upload' was called.");
? response.writeHead(200, {"Content-Type":"text/plain"});
? response.write("You've sent the text: "+
? querystring.parse(postData).text);
? response.end();
}

function show(response, postData) {
? console.log("Request handler 'show' was called.");
? fs.readFile("/tmp/test.png", "binary",function(error, file) {
? ? if(error) {
? ? ? response.writeHead(500, {"Content-Type":"text/plain"});
? ? ? response.write(error + "\n");
? ? ? response.end();
? ? } else {
? ? ? response.writeHead(200, {"Content-Type":"image/png"});
? ? ? response.write(file, "binary");
? ? ? response.end();
? ? }
? });
}

exports.start = start;
exports.upload = upload;
exports.show = show;

? ? route(handle, pathname, response, request);
? }

? http.createServer(onRequest).listen(8888);
? console.log("Server has started.");
}

exports.start = start;

? if (typeof handle[pathname] === 'function') {
? ? handle[pathname](response, request);
? } else {
? ? console.log("No request handler found for " +pathname);
? ? response.writeHead(404, {"Content-Type":"text/html"});
? ? response.write("404 Not found");
? ? response.end();
? }
}

exports.route = route;

? ? '</head>'+
? ? '<body>'+
? ? '<form action="/upload"enctype="multipart/form-data" '+
? ? 'method="post">'+
? ? '<input type="file" name="upload"multiple="multiple">'+
? ? '<input type="submit" value="Upload file"/>'+
? ? '</form>'+
? ? '</body>'+
? ? '</html>';

? ? response.writeHead(200, {"Content-Type":"text/html"});
? ? response.write(body);
? ? response.end();
}

function upload(response, request) {
? console.log("Request handler 'upload' was called.");

? var form = new formidable.IncomingForm();
? console.log("about to parse");
? form.parse(request, function(error, fields, files) {
? ? console.log("parsing done");
? ? fs.renameSync(files.upload.path, "/tmp/test.png");
? ? response.writeHead(200, {"Content-Type":"text/html"});
? ? response.write("received image:<br/>");
? ? response.write("<img src='/show' />");
? ? response.end();
? });
}

function show(response) {
? console.log("Request handler 'show' was called.");
? fs.readFile("/tmp/test.png", "binary",function(error, file) {
? ? if(error) {
? ? ? response.writeHead(500, {"Content-Type":"text/plain"});
? ? ? response.write(error + "\n");
? ? ? response.end();
? ? } else {
? ? ? response.writeHead(200, {"Content-Type":"image/png"});
? ? ? response.write(file, "binary");
? ? ? response.end();
? ? }
? });
}

exports.start = start;
exports.upload = upload;
exports.show = show;

幸运的是,Node.js社区非常活跃(作个不恰当的比喻就是犹如一群有多动症小孩子在一起,能不活跃吗?), 这意味着,有许多关于Node.js的资源,有什么问题都可以向社区寻求解答。 其中Node.js社区的wiki以及 NodeCloud就是最好的资源。

热点排行
Bad Request.