Which functions would Node js do better
Node.js: what is it? Functions, application & basics
- Node.js: what is it? Functions, application & basics
Node.js acts on the server and works on an event basis. What exactly does event-based mean? In the context of web development, an event is an action that can be reacted to. Events can be divided into categories, for example user-based events such as a mouse click, keyboard or voice input. Another category would be the application-generated events, for example when an HTTP call or file access has been completed. The program can react to these actions, i.e. one or more subsequent actions can be carried out with a mouse click.
Node.js in the application
Due to its event-based properties, Node.js is a popular choice in web server development. For a long time, servers were thread-based and not event-based. But what difference does that make? An example:
There is a long queue in a fast food restaurant. The person at the checkout orders their food and then stays in line until their order is ready. The cash register cannot process any further customers during this time. This would be equivalent to thread-based servers. An event-based server would work as follows: There is a long queue again in our fast-food restaurant. The person at the checkout orders their food and then goes to another place to wait for their order. So the cash register can process the next customer. As soon as the order of the first customer is ready, he will be notified and can pick it up. This principle is well known to us and also works efficiently in real life.
Attentive readers will now find that event-based processes pose a risk of blockages. In our fast food example, this could be done through online orders, for example, which slows down the process of on-site customers.
With Node.js it is possible to ensure that no blockages arise during these events. The entry and exit of the events must not be obstructed, this is then called non-block I / O.
It is also possible to create software far outside of web development. So scripts can be created for the command line and desktop applications. As with any other all-rounder language, caution applies here too. Because the mere possibility of wide-ranging use does not guarantee security or elegant solutions.
This feature is also known under the term Non-blocking I / O. The aim was to avoid synchronous threads, which start a separate thread for each request and block the entire process. In this way, Node.js no longer helps the web server start individual threads. Instead, so-called single threads are started with Node.js. These are then processed one after the other in an endless loop.
The endless loop for processing single threads is implemented by the Libuv component. This library creates a thread pool of size 4 by default. By default, up to four threads can be processed at the same time. In addition, Libuv sends requests to the operating system, which takes care of the timing of the threads. Actions can be carried out without waiting for a previous action. For example, the website can continue to be generated while waiting for API requests at the same time.
With the help of the event stack, these actions are sorted and processed continuously. This happens after LIFO- Pattern: Last In, First Out. This event stack, also called the event loop, waits for a function to be executed in the stack. At the same time, new functions are added to the stack.
Server and client
Node Package Manager (npm)
Node.js already installed a number of extremely useful modules when it was first installed. For example, the url module with which functions are added, which simplify the work with URLs. To add further modules for your own individual purpose, there is the Node Package Manager (npm). This is also available during the initial installation. With an overwhelming number of more than 350,000 parcels, no wish is left out. But caution is also advised. With this number of modules, there are some black sheep, which in the best case simply do nothing, although they promise otherwise. In the worst-case scenario, they access user data, which has already happened in the past.
But how do you recognize a good npm module? It can be helpful to look into this Github- Take a closer look at the repository.
- Does the profile of the person or company who developed it look trustworthy?
- How many stars (Stars) received the project? Because:
In particular, the widely used modules will have a high number of stars. It becomes more difficult to check this for special and unique use cases. The more exotic the requirements, the less often such a module is called.
- Are there contributors who helped develop or improve part of the module?
- How often found a Commit instead of?
Do you need a WordPress agency? We are available as your experts. Get in touch with us and arrange a non-binding consultation.
- An empath can learn to be selfish
- Is the recruiting process at Amazon too tough
- Why did Brendan Rodgers fail in Liverpool
- Hollywood stars sleep to get roles
- Are Poshmark ratings public
- What is the youngest NBA team
- Which antibiotic is best for a sore throat
- Why do electrons go
- What's the best bar in Oklahoma
- Nestor University is an accredited school
- What is the importance of the company
- Why do big technology companies fail
- How to file public interest disputes
- Which Indian actors and actresses are unmarried
- Why is formaldehyde sometimes called formol
- Why are books reliable sources?
- How can I prevent dark urine
- Which instrument measures pressure
- Why are purple cars unusual?
- Are psychiatrists vicious
- Sells Tesla Motors used Teslas
- How come some people refuse to work
- How is success in music determined
- What is Sarah Palin's SAT Score
- Is the IBM I AS400 dead
- Does the computer's power supply affect its performance
- Do we have free will 5
- How many kilometers is a mile
- What is the CSIO ISTC paper sample
- How to Compare Decimal Places
- Why is UCLA so popular
- How did DNA and protein interact
- How does trout taste