How to Develop Web Application using pure Node.js (HTTP GET and POST, HTTP Server)



-How to create HTTP Server using Node.js
-How to do HTTP GET using pure Node.js
-How to do HTTP POST using pure Node.js
-How to develop web applications using pure Node.js
-How to use StringBuilder in Node.js
-How to use QueryString parser in Node.js
-How to send HTTP status codes in Node.js

Nguồn: https://indiancinema-analysis.com/

Xem thêm bài viết: https://indiancinema-analysis.com/category/cong-nghe

Related Post

25 Replies to “How to Develop Web Application using pure Node.js (HTTP GET and POST, HTTP Server)”

  1. So nice to see a 'no frills' version of this that explains so much. There are times when you don't really want or need all the framework stuff … good job!

  2. Interesting video, but be carefull on coupling http://foobarbaz.club/this-is-why-coupling-is-your-worst-enemy/

  3. Is this "pure Node.js", if a stringbuilder (or any other) dependency (package) is used? I'm not quite sure.. Stringbuilder is dead since 2015 and has only 204 downloads a week on npmjs. I also think that having the server write the same piece of HTML, line by line, with every request (happens from 37:35) are a no go in the real world.

  4. I want to output this Hello World on my Website already Hostet by a Hoster can you show us this? So Run my Node.js Program and see output on mywebsite.com

  5. var http = require("http");
    var qs = require("querystring");
    var StringBuilder = require("stringbuilder");

    var port = 9001;

    function getHome(req,resp){
    resp.writeHead(200,{"Content-Type":"text/html"});
    resp.write("<html><head><title>Home</title></head><body>Need to add some values? Click <a href ='/calc'>here</a></body></html>");
    resp.end();
    }
    function getCalcForm(req,resp){
    var sb = new StringBuilder({ newline: 'rn'});

    sb.appendLine("<html>");
    sb.appendLine("<body>");
    sb.appendLine(" <form method='post'>");
    sb.appendLine(" <table>");
    sb.appendLine(" <tr>");
    sb.appendLine(" <td>Enter the FIRST Value</td>");
    sb.appendLine(" <td><input type='text' id='txtFirstNo' value=''/></td>");
    sb.appendLine(" </tr>");
    sb.appendLine(" <tr>");
    sb.appendLine(" <td>Enter the SECOND Value</td>");
    sb.appendLine(" <td><input type='text' id='txtSecondNo' value=''/></td>");
    sb.appendLine(" </tr>");
    sb.appendLine(" <tr>");
    sb.appendLine(" <td><input type='submit' value='Calculate'/></td>");
    sb.appendLine(" </tr>");
    sb.appendLine(" <tr>");
    sb.appendLine(" <td><span>Sum=</span></td>");
    sb.appendLine(" </tr>");
    sb.appendLine(" </table>");
    sb.appendLine(" </form>");
    sb.appendLine("</body>");
    sb.appendLine("</html>");

    sb.build(function(err,result){
    resp.writeHead(200,{"Content-Type":"text/html"});
    resp.write(result);
    resp.end();
    });
    }
    function get404(req,resp){
    resp.writeHead(404,"Resource not Found",{"Content-Type":"text/html"});
    resp.write("<html><head><title>404</title></head><body>404 Resource not found Click <a href ='/'>home</a></body></html>");
    resp.end();
    }
    function get405(req,resp){
    resp.writeHead(405,"Method Not Supported",{"Content-Type":"text/html"});
    resp.write("<html><head><title>405</title></head><body>405 Method Not Found Click <a href ='/'>home</a></body></html>");
    resp.end();
    }
    http.createServer(function(req, resp){
    console.log(req.url);
    switch (req.method){
    case "GET":
    if(req.url==="/"){
    getHome(req,resp);
    resp.end();
    }
    else if (req.url==="/calc"){
    getCalcForm(req,resp);
    resp.end();
    }
    else{
    get404(req,resp);
    resp.end();
    }
    break;
    case"POST":
    break;
    default:{
    get405(req,resp);
    }
    break;
    }
    resp.end();
    }).listen(port);

    this code is throwing this error

    Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at write_ (_http_outgoing.js:580:17)
    at ServerResponse.write (_http_outgoing.js:575:10)
    at C:Usersadminhttpsample.js:21:8
    at C:Usersadminnode_modulesstringbuilderlibstringbuilder.js:212:4
    at C:Usersadminnode_modulesstringbuilderlibstringbuilder.js:192:7
    at C:Usersadminnode_modulesstringbuilderlibstringbuilder.js:351:4
    at C:Usersadminnode_modulesasynclibasync.js:232:13
    at C:Usersadminnode_modulesasynclibasync.js:119:25
    at C:Usersadminnode_modulesasynclibasync.js:24:16
    at C:Usersadminnode_modulesasynclibasync.js:229:17
    Emitted 'error' event at:
    at writeAfterEndNT (_http_outgoing.js:639:7)
    at process._tickCallback (internal/process/next_tick.js:63:19)

    Please let me know what is this error stating. the error occurs on clicking the /calc page
    Code is almost as you have written

  6. this is some high-end stuff…
    im a beginner in this field…but i have good flow in html and css and intermediate js….so i would type the html the way u did…just to learn this diamond stuff..string builder…

    damnn i wish i could sync my mind with yours….:( i live in new delhi….

  7. Very good tutorial for a beginner. Do you also have a video where we are building the front end using angular that uses a Javascript backend web service just like this one?

  8. why cant we create a html page and reffering that page…its too difficult to write html code in stringbulder and attaching there…please if possible to redirect to html page please help me…

Leave a Reply

Your email address will not be published. Required fields are marked *