Skip to content
/ node Public

β˜• Small node.js applications to practice and brief explanations about

License

Notifications You must be signed in to change notification settings

FelipePDS/node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

50 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Node.js

ABOUT πŸ“ƒ

Here I show a brief explanation about Node.js, where I leave a list of exercises and small applications made in Node.js to practice 😊


SUMMARY πŸ“‹


1. WHAT'S THE NODE.JS

To understand Node.js it is very important to know about Javascript. Knowing this, it is easy to understand that Javascript is compiled by browsers to make it work, as is the case with Chrome that has "at its heart" the "little engine" V8, which compiles the Javascript code to execute all its commands on the machine anyone. However, today it is no longer necessary to depend on browsers to execute Javascript, because with Node.js it is possible to compile Javascript directly on the machine of the person who had it (development environment), providing many resources and with a functioning that allows to perform things in the Backend that makes it more unique 😎. With this functioning in a separate browser environment, it is possible to create servers, APIs and much more involving Node.js.

Its operation is explained below, saying more how Javascript reads the code and what it influences on the quality of the code result...

1.1 How It Works

The compilation of Node.js works asynchronously, that is, it reads all the code "at once", that is, it does not block with each block of code, it can read them all very quickly, but when there is a block of code with a set time to execute, it does not wait for you to proceed to read the rest of the code, and when the time needed to execute it runs out, it executes without problems. A very basic example of this...
In Javascript we have the function setInterval(), where the code block executed as its first parameter will execute after a certain time in milliseconds which is indicated as the second parameter in the function, as a result of the following example we see that the first code block executes after the given time (milliseconds) in the second parameter of the setInterval function, and even if that code block is coming before the other code block marked as a function named secondBlock(), it ends up being executed only afterwards with the message returned in the console , as it is determined to run after a certain time:

function firstBlock() {
    setTimeout(() => {
        console.log("This is the First Block");
    }, 3000);
}

function secondBlock() {
    console.log("This is the Second Block");
}

firstBlock();
secondBlock();

// Result returned on the console:
// This is the Second Block
// This is the First Block

As we can see, the second block of code executed first, since the first code was determined to be executed after 3000 milliseconds in setInterval

With this information in hand, it is good to see what callback is in Javascript and also to train your practice to have a good understanding.

To make this asynchronous operation that Javascript has more clear, let's go to a classic example to explain this:

Imagine how the service of a waiter works to take and take orders (called commands) from customers to the kitchen. He will basically go to the table of a customer who arrived, will take his orders, and take the command to the kitchen, continuously he will do this with other customers who have not yet been served, regardless of the order of the other customer not yet have arrived at his table. So the waiter does NOT need an order from a customer to be ready for him to deliver it and thus proceed to serve another customer, he just goes on serving other customers while the orders are being placed in the kitchen and when any order is ready, he finishes what you are doing at the moment and will take the order to the table of the customer who requested it.

This explains in a more simplified way what was said above, that is, a single thread, which can be used, for example, in the request of a Database, where a user makes a request that is necessary to consult the Database of application, calling an Asynchronous function that will have a specified process to do something when the database query processing is finished, that is, so when that Asynchronous function is performed, a callback will be added to a list of functions to be executed , so it will be executed by doing what has been specified to it. So thanks to this, it is possible to receive several threads at the same time, that is, while the user sends a request that it is necessary to consult the database as explained above, he can carry out other things, without being interrupted (a process called a non-blocking single thread).

1.2 Advantages

Its great advantage in relation to its operation is the intense sending and receiving of data with the server made in Node.js, gaining a great speed and more performed performance, that is, a non-blocking thread

Node.js also has a great advantage in relation to development, as it offers a multitude of resources and mini libraries that use it, this supply occurs through the NPM (Node Package Manager), which basically manages packages in Node.js to facilitate in some developments, using only the terminal, it is possible to import for the development of some project, a multitude of packages that it stores, as a mini framework that facilitates the development in Node.js, which is Express:

$ npm install express

When executing this command with Node.js on your machine, it will create a prototyped Express project developed in Node.js, with a development package of it called node_modules, with the modules and configurations to develop the project in Node.js

All of this makes it possible to have a much cleaner, smaller and more structured code...

1.3 Its Use

Node.js has been widely used in the programming world since its creation in 2009, due to the simple fact that it offers a working solution that fits very well for many situations such as API creation or Backend development, always accompanied with queries. , requisitions and Promises coming from the Database mainly.

All of this as said, drew the attention of many companies, who used it, such as Netflix, Uber, Linkedin, Nasa, PayPal and more...


2. HOW TO USE NODE.JS

To use Node.js, you only need Node.js itself and a code editor, in which case Visual Studio Code is highly recommended, because with it you can run many things, such as Node.js itself, or use the terminal to add packages to the project with NPM

2.1 Install πŸ’Ύ

To install Node.js correctly, it is important to follow the step-by-step to make it possible to use NPM on your machine, which will make your projects much more practical and better.

1. Download β†’ Node.js

2. Open the downloaded file for your installation

3. When following the installation steps in the setup, it is important to leave the inclusion of NPM checked

When finished, give the node --version and npm --version command on the terminal to verify that they have been installed correctly

2.2 Running a small application in Node.js 🎲

The main functionality of Node.js is to work with Modules and HTTP.

See the Rocketseat Node.js Masterclass


3. APPLICATIONS WITH NODE.JS πŸ’»

Here I leave some small projects done in Node.js to practice, if you want to see them or want to use them as an idea to develop something and practice, I leave them to clone.

3.1 Getting Started With Node.js (study topics)

The simplest way to understand Node.js, as well as many things in programming, is to practice, taking the resources it offers and manipulating them to see how it works...

3.2 Exercises To Practice The Node.js ✏️

Click on the exercises and small projects to view their objectives and resolutions, and if you want to clone them, there is an explanation on.

3.2.1 How To Clone The Exercises πŸ“‚

If you want to clone one of the exercises (subdirectories), just have git bash on your computer to give the following commands

# Create a folder with the name of the exercise and enter it
$ mkdir name-dir && cd name-dir

# Start a git repository to access the repository
$ git init

# Crawl the repositorie
$ git remote add -f origin https://github.com/FelipePDS/node

# Active sparse checkout
$ git config core.sparseCheckout true

# Create a file in the path: .git/node/sparse-checkout
# And insert the name of the subdirectory you want to clone
$ echo 'nameOfTheSubdirectory' >> .git/node/sparse-checkout

# Pull the subdirectory
$ git pull origin main
Font: terminalroot.com.br

If you want to clone the entire project: $ git clone https://github.com/FelipePDS/node.git

3.2.2 Exercises List

EXERCISE DESCRIPTION
01_modules Learning about node.js module imports and exports feature
02_http Creating server with node.js http
03_jobsCalc Starting rocketseat discover project to practice node.js

Now is to practice Node.js and become a master using it... πŸ˜†

GIF Programming

4. REFERENCES βš“


5. AUTHOR πŸ‘€

This repository was made by
FelipePDS ❀️

MIT License β€’ Β© FelipePDS

About

β˜• Small node.js applications to practice and brief explanations about

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published