Hey, guys! If your habit is to learn something deeply and thoroughly, this article is for you. Here we will try to answer the questions that you will have sooner or later in the process of development. These answers require deep understanding of how Node.js works. For example, here (serverAsync.js see the files of our previous lesson) an asynchronous call is used for reading a file:
In real life you will barely witness a situation, when once a request has been received, the server can immediately respond it. To do so, the server generally needs some data. These data can come from a database or another source – for example, a file system. In our example, when using the fs module upon receiving a request at url '/', the file index.html is being read and outputted to a visitor
We will further refer to the http module quite often, so let us now explore its supporting materials, what we can find there and where. Right now the http module combines two functional services. The first one is the server functionality. http.createServer creates a new object of a Server class. If a handler is transmitted, it will go to the request event. The second functional service is createClient.
Hey all! This lesson will be devoted to the echo server creation. This is a server that brings up the parameter meaning upon the url/echo request with the message parameter: // http://127.0.0.1:3000/echo?message=Hello -> Hello The answer to all other requests will be: Page Not Found. Let us start from a template of this kind:
Hey all! This time we will meet Node.js as a web server. So, let us create a new app for that purpose. Set up your editor in a way it would know you’re working on a Node.js project and support the respective auto-additions and global variables. Next let us create server.js and connect a module as the very first step:
The next object we are interested in is EventEmitter, or, as it is sometimes called, EE. EventEmitter is a basic object that executes work with events in Node.js. A great number of other built-in objects generating events inherit from it. To use EventEmitter you only need to connect the built-in “events” module and take a respective property from it (let us create ee.js);