Ambiente di sviluppo JavaScript

Node.js

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

History

Created By Ryan Dahl in 2009

 

https://youtu.be/ztspvPYybIY

v0.12.17 ==> v4.0.0

Joyent sponsored the project from the beginning

At the end of 2014 Fedor Indutny forked Node.js and created io.js

io.js was created as an open governance alternative with a separate technical committee

io.js started using a semantic versioning for the project

In September 2015, Node.js v0.12 and io.js v3.3 were merged back together into Node v4.0

Features

NPM

NPM stands for node package manager

is the largest ecosystem of open source libraries in the world.

npmjs.com

NPM invites the developers to use semantic versioning, aka semver

{
  "name": "our-dummy-project",
  "version": "0.0.1",
  "description": "This is a dummy project",
  "main": "index.js",
  "author": "extrategy",
  "license": "MIT",
  "scripts": {
    "start": "http-server"
  },  
  "dependencies": {
    "lodash": "4.17.2"
  },
  "devDependencies": {
    "http-server": "1.0.0"
  }  
}

a package.json file

NPM commands

npm init
npm install / uninstall
npm run x
npm publish / unpublish

NVM

NVM stands for node version manager

USE IT!

nvm.sh

nvm ls / ls-remote

nvm install /uninstall

nvm use

.nvmrc

Event loop

JavaScript has no threads

All I/O operations in Node.js are non-blocking

High Performances

Callbacks

Error-first Callbacks

AKA node-style callbacks

Task Runners

Applications that automate time consuming and boring tasks

Make your life easier when developing for the front-end by automating tasks

- compile modified SASS to CSS

- minify javascript and CSS files

- watch for changes

- run tests

...

Created by Ben Alman in 2012, written in node.js, distributed via npm

Thousands of plugins

gruntjs.com/plugins

Tasks defined by configuration

gruntfile.js

Ability to define custom tasks, which can combine multiple existing tasks into a single task or add entirely new functionality

Processed files are stored in tmp folders and then passed as imput to the next task, and so on

LOT OF I/O CALLS

Similar Grunt modular architecture and plugins system

gulpjs.com/plugins

Tasks defined by code

gulpfile.js

Uses node streams: gulp reads the fs directly and passes the data via .pipe() to the next plugin

No use of tmp folders, decreasing the number of I/O calls, improving performance

Defines itself as a
"module bundler"

It splits your app into multiple files. If you have multiple pages in a single-page app, the user only downloads code for just that page. If they go to another page, they don't redownload common code

from this...

...to this

The result is clean, reusable code. Each individual component depends on import-ing its own dependencies, and export-ing what it wants to make public to other modules

Useful links

That's It!

Thanks!

Ambiente di sviluppo JavaScript

By extrategy

Ambiente di sviluppo JavaScript

  • 1,533