pengenalan dasar nodejs

20
NodeJS Introduction Alfi Setyadi Mochtar Dignot.com engineer

Upload: alfi-setyadi

Post on 16-Jan-2017

150 views

Category:

Technology


0 download

TRANSCRIPT

NodeJS IntroductionAlfi Setyadi Mochtar

Dignot.com engineer

Sejarah Pribadi

Belajar Java (J2SE) – 2007 Belajar PHP – 2009 Belajar nodeJS – 2013 Belajar Go - 2016

NodeJS

Ryan Dhal pada tahun 2009 Javascript bisa digunakan sebagai bahasa pemrograman di sisi server

seperti halnya PHP, ASP, C#, Ruby dll dengan kata lain “Node.js” Menggunakan engine v8 yang dibangun oleh Google dan digunakan

pada browser Google Chrome 

Javascript ITU BUKAN Java

Asinkron I/O & Event

Multi Thread – Blocking I/O

Single Thread – non Blocking I/O

Event Loop

Contoh: PHP - synch

$hasil = mysql_query("SELECT * FROM TabelAnggota"); print_r($hasil);

JS

var fs = require('fs'); fs.readFile('./resource.json',function(err, data){ if(err) throw err; console.log(JSON.parse(data)); }); console.log('Selanjutnya...');

Output:

Selanjutnya...Isi dari file resource.json

NPM

Benchmark PHP<?phpecho 'Halo Dunia!';

Requests/sec: 340.74

Benchmark – NodeJS + expressJSRequests/sec: 3605.82

Benchmark NodeJS pure httpRequests/sec: 5124.83

Benchmark GORequests/sec: 14558.87

Repo:

https://github.com/allfix53/benchmarking

Cons – “He said”

Node.js doesn’t provide scalability. One CPU is not going to be enough; the platform provides no ability to scale out to take advantage of the multiple cores commonly present in today’s server-class hardware.

Dealing with relational database is a pain if you are using Node. Every time using a callback end up with tons of nested callbacks. Without diving in depth of JavaScript if someone starts Node, he may

face conceptual problem. Node.js is not suited for CPU-intensive tasks. It is suited for I/O stuff

only (like web servers).

“Node.js adalah sebuah solusi untuk membuat sebuat aplikasi jaringan yang bisa menangani jumlah koneksi yang banyak, melakukan pertukaran data yang banyak, dan melakukan komunikasi client-server secara real-time”

Terimakasih…