Programming/node.js2014. 9. 13. 11:44

메뉴얼 사이트

 - Application :  http://expressjs.com/api.html#express

 - Request : http://expressjs.com/api.html#req.params

 - Response :  http://expressjs.com/api.html#res.status

 - Router : http://expressjs.com/api.html#router

 - Middleware : http://expressjs.com/api.html#middleware.api


테스트 샘플자료 (자세한 내용은 위에 API 참조하면 방대함 정규식처리등 많음)

  1. var express = require('express'), http = require('http');
  2. var bodyParser = require('body-parser');
  3. var app = express();
  4. app.use(bodyParser());
  5. app.all('*', function( req, res, next){
  6. res.writeHead(200,{
  7. "Content-Type" : "text/plain"
  8. });
  9. next();
  10. });
  11. app.get("/", function( req, res){
  12. res.end("HOME DIR : /");
  13. });
  14. app.get("/test", function( req, res){
  15. res.end("HOME DIR : /test");
  16. });
  17. app.get("/params/:user", function( req, res){
  18. var sText = " Params : "+req.params.user; // OR req.param('user')
  19. sText += "\n GET : "+req.query.q; //search?q=test OR req.param('q')
  20. sText += "\n POST : "+req.param('name'); //POST name=tobi
  21. //sText += "Cookie : "+req.cookies.name; // Cookie: name=tj
  22. sText += "\n ip : "+req.ip; // req.ips When "trust proxy" is `true`, parse the "X-Forwarded-For"
  23. res.end(sText);
  24. });
  25. app.get("*", function( req, res){
  26. res.end("NOT PAGE");
  27. });
  28. http.createServer(app).listen(80, '127.0.0.1');
  29. console.log('HTTP URL : http://127.0.0.1:80/');


Posted by 시니^^