Toll-free number 24/7:

+38 (097) 806-01-89

Customer Service e-mail:

Introduction to Node.js

February 21, 2018

Introduction to Node.js

Each experienced developer knows very well all aspects of JavaScript that is a programming language. It is this programming language that is used for the Node.js platform. Node.js - is fairly young platform, but already has several versions. Last, the 8th version was released in 2017 on the 30th of May. There are different versions of the platform that use by the file manager Node.js -nvm(node version manager). To choose new version we may with the CLI API. The Node.js platform facilitated the use of JavaScript as a general use language that was before only in the browser language.

Node.js - is a platform for working with applications in the JavaScript language. Node.js is an easy and efficient platform for event-driven O/I models. You can find Node.js at this address:

The peculiarity of this platform is open source code that opens endless possibilities for each developer to work. Node.js is impressive with its versatility and a variety of features and modules. The main purpose of Node.js is the code s interpretation and its execution for access outside of the browser. To compose the JavaScript code, this platform is powered by an open-source code engine - Google V8. Thanks to the asynchronous code run on Node.js, a large number of queries can be processed at the similarly time.

Let's see how the Node.js works and write our first phrase.

Take “Hi Friends” for an example. To get started - open the application you are using and produce a hifriends.js file in it. Then you must to bring out our line in the console, for this creates the next text:

сonsole.log ('' Hi Friends ''); 

Than you must to save the created file and execute it as Node.js:

node hifriends.js

As the result we have to get "Hi Friends" directly on the screen. That's how it starts working with this platform.

And what exactly does Node.js need to work on your gadget?

In order for this platform to be realized, we must to use an HTTP server. But that is not enough! We already know that Node.js allows many queries to be served simultaneously, so for this function we need a router and a handler of these queries (inputs, downloads). As well as for query processing, we need the so-called display logic so that the user can see its content at the request of the URL.

The best Node.js feature is that, unlike other similar applications, Node.js works closely with the HTTP server as if it were one. This is due to the implementation of this server in Node.js. Another feature of this platform is the modules. That is, they make up the code itself. Thanks to the ability of the code to be split into the module, we will have clean modules and a master file that can use them, and each module can use a clean module.

Let's look at an example of a more complex phrase in Node.js already with an HTTP server.

Create a master file that I call reporter.js, and the server code is appropriately called server.js. First we will create the server module - server.js. Create a server.js file in the core of the directory and type the next code there:

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hi Friends");

Our HTTP server is ready! Now you must to run it and test it. To do this, execute the script in Node.js:

node server.js

Then open the browser and go to the address: http: // localhost: 8888 /.

If you have done everything correctly, then select the web page with the phrase "Hi Friends".

Now we can start the HTTP server in the main file - reporter.js.

Create reporter.js. file and fill it with the next code:

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

server.start ();

Done - now you launch it through the main code:

node reporter.js

From now on, we can already perform various file operations: move parts of the code into different files, link them in the module.

We looked at just a simple example of how to work with Node.js, you can use it when creating other files. So, we can say that this is a special and easy to use platform with many features and aspects. With its appearance, it changed the impression of such a familiar JavaScript language for the better, showing it on the other side.

If you need an open source platform for client and server applications - Node.js is for you!

Other Articles

Our Recommendations

  • October 11, 2017
    Creating a “turnkey” website (Development)

    Creating a “turnkey” website includes a set of works related to its development, content with content, testing, placement, administration and promotion.

  • August 30, 2017
    AJAX-develpment (Development)

    The abbreviation AJAX decrypted as Asynchronous JavaScript and XML. As we see, this technology combines several related technologies. They include: PHP HTML CSS JavaScript and оthers.