A Way to Use Express in Node.js

  • Getting started:
    var express = require(‘express’);
    var app = express();
    This is some kind of rule to use to node.js.
  • app.get(‘/’, function(req, res){});
    When a user try to connect to ‘/’ path using GET method, function(req, res) is excuted. Parameter request, response is node.js rule.
  • url anatomy:
    http — Protocol
    a.com — Domain
    classes — Path
    username=joo — Query string
  • Query string url:
    if (path === “/classes?username=joo”) { response.query.username}; // response.query.username is joo
  • Semantic url:
    Some kind of expression url instead of query string because readability. example — http://a.com/classes/joo
    In javascript file, this is 
    if (path === “/classes/:username”) { response.params.username}; // response.params.username is joo
    * username is custom html tag name
  • req.body:
    This is useful method by requiring Middlewares body-parser or multer in Node.js. It makes easy to handle post request and response. If it is required, every request of POST is able to have .body object. 
    Request.body have a various object get by other data like html, controller of MVC model.
Show your support

Clapping shows how much you appreciated Minoo Joo’s story.