Skip to content

dragonstin/NodeJS

Repository files navigation

About

Studying Node.js through the NodeBR course.

Versão em Português-BR


A little bit of concept

Node.js

  • Created by Ryan Dahl in 2009. Node.js is a platform for building backend applications using JavaScript.

NPM

  • NPM (stands for Node Package Manager) is responsible for managing the dependencies(package.json) of the project.

Installation

  • Install Node.js in your computer https://nodejs.org/en/.
  • Run the command node --version, to check the version of the node that is installed on your computer.

Starting a project

  • To start a node.js project, run the command npm init (or npm init -y to run as the default settings).

Using NPM to write a line commands

NPM also can be used to write line commands.

In the package.json file:

"scripts": {     "dev": "node index.js" },

In this code snippet, it is showed the function "dev".

To execute line commands with NPM it is used the command npm run "name-of-your-function", with base of the code above, it would be npm run dev.


Life cicle of JavaScript

  • Functions that need external resources (access to database or files) will be running in the background.
  • The code does not run sequentially.
  • Remember to keep the sequence of your program to avoid problems.

Life cicle of Promisses

  • Pending: Initial state, not yet finished or not rejected yet.
  • Fulfilled: After performing all operations successfully.
  • Rejected: Operation failed.

Promises - ASYNC/AWAIT

Async The word “async” before a function means that this function always returns a promise. Await it just works only inside async functions and makes JavaScript wait until that promise settles and returns its result.

  • It makes it easy for the visualization of the flow of functions.
  • It does not change the performance of your application (if used correctly).
  • Already existing in C # was developed in JavaScript.
  • Use only when you need to wait for the call's answer (Await).

Event Emitter

  • Used for continuous actions.
  • Node.js uses for almost everything in your ecosystem.
  • Quite also used in browsers (.onClick).
  • It work under Design Pattern Observer / PubSub]

Test cycle settings

  • npm init -y -> Start Node.js project
  • npm install axios -> Insall Axios Lib
  • npm install -g mocha -> Install Mocha globally
  • npm i --save-dev mocha -> Install Mocha as a development dependency
  • npm install nock -> Install the Nock package. It's used to simulate requests

Creating line commands tools

About

Repository to study Node.js.

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors