Node.js
Álvaro José Agámez Licha
Software Developer en PSL
https://github.com/CodeMaxter
@codemaxter
Open Source Server Enviroment For Your JavaScript Apps
What is Node.js
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine, or Microsoft ChakraCore.
- Is an open source server environment.
- Runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.).
- Uses a lightweight and efficient event-driven, non-blocking I/O model.
Node.js is a single threaded language which in background uses multiple threads to execute asynchronous code.
Node.js is fast and efficient because use a single thread:
- Thread-based networking is relatively inefficient,
- Thread-base is very difficult to use.
- Users of Node are free from worries of dead-locking the process, since there are no locks.
Node = Not Single Threaded
Event Loop = Single Threaded
- Multiple Threads run in parallel and this is true of Node.
- The event loop processes events in a single thread concurrently.
Everything in JavaScript runs parallel except your code. Your code executes one thing at a time even when other workers are doing their jobs concurrently.
Installation
The Package Manager
Open your terminal and type the following:
Installing a Package Globally
npm install -g jshint
This will install the jshint package globally on your system. We can use it to lint a es6.js file:
jshint es6.js
We can also install packages locally to a project, as opposed to globally on our system. Create a test folder and open a terminal in that directory. Next type:
Installing a Package Locally
npm init -y
This will create and auto-populate a package.json file in the same folder. Next, use npm to install the lodash package and save it as a project dependency:
npm install lodash --save
Node.js Introduction
By Alvaro Agamez
Node.js Introduction
- 513