Alwin Arrasyid
Software Engineer @dycodex, FOSS enthusiast.
everywhere
Alwin Arrasyid, 19 years old.
Node.js Developer at DyCode / DycodeX.
Sometimes do DevOps things.
10th gen. of RPL SMKN 1 Cimahi.
Dedicated app for movie freaks. Available for iOS, Android, and Windows Phone!
Photo collecting, management and printing solution for venues and events.
A Smart Drinking Water Monitoring Platform
Your Everyday Thermal Printer. Only Smarter.
Personal butler. Now in your hand.
Javascript runtime built on top of Google Chrome's V8 engine.
Node.js uses asynchronous, event-driven, non-blocking I/O.
Firstly developed by Ryan Dahl at Joyent.
Now is developed and maintained by community under control of Node.js Foundation.
Yes! The thing is, Node.js lets you run javascript code out of the browsers!
Or Javascript in general
From large-scale back-end, mobile apps to distributed IoT devices!
The "Full Stack" terms in node.js has changed from back-end and front-end to back-end, front-end and interconnected devices!
With those frameworks, you are able to build service-based back-end easily for your mobile apps and IoT devices!
In this field, Node.js acts as a platform, and build system along with other build system like gradle, etc.
Tired of using Java or .NET to build desktop application? Try Electron!
Node.js can also be used as a tool of developing front-end web app or libraries.
You don't need Node.js to develop Tizen app, but it uses javascript, html and css!
Node.js is everywhere!
It uses asynchronous I/O model!
Node.js uses async I/O model. It doesn't block the event loop so that the next code can be executed immediately!
When we call async function, we need to provide a callback function that will be executed once the async operation is finished.
// simulates user data retrieval from database
function getUser(userId, callback) {
db.User.findById(userId, function(err, result) {
if (err) return callback(err);
return callback(null, result);
});
}
// main code
console.log('Getting user data...');
getUser(1, function(err, result) {
if (err) {
console.error('There was an error:' + err.message);
return false;
}
console.log('User data: ' + user.name);
});
console.log('done');
<?php
// db connection initialization code here....
$queryResult = mysqli_query('SELECT * FROM user WHERE id = 1');
$userData = mysqli_fetch_assoc($queryResult);
?>
Compare with this piece of PHP code
What you've seen is one of some async workflows in Node.js. Actually, there's more!
Promise is an eventual value that can be returned immediately from an async function. Promise utilize then and catch method to signal result or error of an async operation .
Promise is chainnable! You can chain a sequence of async operations.
function getUser(id) {
return new Promise(function(resolve, reject) {
db.User.findById(id, function(error, result) {
if (error) return reject(error);
return resolve(result);
});
})
}
getUser(id)
.then(function(result) {
console.log('User: ' + result.name);
})
.catch(function(rejection) {
console.error('Caught error: ' + rejection.message);
});
function getUser(id) {
// simulates async operation
return Promise.resolve({ name: 'alwin', id: 1 });
}
function getUserJob(user) {
// simulates async operation
return Promise.resolve({
job: 'Node.js Developer',
user: { name: 'alwin', id: 1 }
});
}
getUser(1)
.then(function(result) {
console.log('User: ' + result.name);
return getUserJob(result);
})
.then(function(job) {
console.log('Job: ' + job.job);
})
.catch(function(rejection) {
console.error('Caught error: ' + rejection.message);
});
Async/await makes working with promise easier!
async function getUserData() {
var user = await getUser(1); // return Promise
var job = await getJob(user); // return Promise, too
console.log('Name: ' + user.name);
console.log('Job: ' + job.job);
}
The code above actually asynchronous, but looks like synchronous!
Node.js is everywhere!
It uses asynchronous I/O model!
Huge support from community & enterprises!
By the end of 2014, there are over 100,000 modules published to npm registry!
source: node.js youtube channel
Announced at the Node Interactive Europe @ Amsterdam event this September.
source: node.js youtube channel
Announced at the Node Interactive Europe @ Amsterdam event this September.
Enterprises become a large part of the community!
twitter: @alwin_wint3r
facebook: facebook.com/alwin.simple
github: github.com/alwint3r
email: alwin.ridd@gmail.com
winter@dycode.com
DyPlex: Jl. Setrasari Kulon II No. 2
(Mon - Fri, 9 AM - 6 PM)
commons.wikimedia.org
microsoft.com
developer.tizen.org
github.com
seeedstudio.com
getchip.com/pages/store
esp8266.com
espruino.com
beagleboard.org
raspberrypi.org
ionicframework.com
cordova.apache.org
krakenjs.com
facebook.github.com
sailsjs.org
feathersjs.com
dycode.co.id
dycodex.com
By Alwin Arrasyid