Node.js: The Ultimate Beginner's Guide to Learn node.js Step by Step | 2020 by John Bach & mEm lnc

Node.js: The Ultimate Beginner's Guide to Learn node.js Step by Step | 2020 by John Bach & mEm lnc

Author:John Bach & mEm lnc [Bach, John]
Language: eng
Format: azw3
Published: 2020-07-23T16:00:00+00:00


route (pathname);

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

response.write ("Hello World");

response.end ();

}

http.createServer (onRequest) .listen (8888);

console.log ("Server Started.");

}

exports.start = start;

And let's extend our index.js properly, that is, injecting our router's routing function into the server:

var server = require ("./ server");

var router = require ("./ router");

server.start (router.route);

Again, we are passing a function as parameters, but this is no longer a novelty for us.

If we start our application now ( node index.js as always), and make a request for a URL, you can see now by the application responses that our HTTP server uses our router and gives it the required path name:

bash $ node index.js

Request for / foo received.

About to route a request to / foo

I have omitted the annoying request response for /favicon.ico



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.