why and how you should move from php to node.js

Post on 07-Jan-2017

2.541 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Why & How You Should Move from PHP to Node.js

Piotr Kowalski CTO @Brainhub

Because it’s 2016!

Because it’s 2016!

Some thoughts about PHP (my personal selection)● Got used to HTTP (rather request processing than application)

● Many PHPisms, inconsise API (past days)

● Many libraries from many sources

● Tremendous community

● Pretty adult

What is JavaScript?

Brief history● Written in 10 (!) days of May 1995 (name: Mocha)

● Deployed in Netscape Navigator 2.0 in December same year

● Standarisation process since 1996 - ECMAScript

● Browser wars

● Many descendants - JScript, ActionScript and so on…

● NOT DEAD!

What is JavaScript not a.k.a. popular myths● Given a web page, add me some animation magic

● Do me some AJAX magic

● Some stuff that cannot be kept tidy

● Works different on every browser

● You write $ then some CSSish selector, then you do stuff

● It’s only for the Web

● Some people call it node, but I have no idea why

● There are no classes, it’s not real OO language

● Everyone knows JavaScript, so why bother?

What about node.js?● A V8 JavaScript engine

● Multiplatform

● Versatile

● Fast (in a runtime)

● Actively developed (current version 7.0.0)

● ...some more

Asynchronous event loop with non-blocking I/O

Asynchronous event loop with non-blocking I/O

Node Package Manager

● Packages count: 344694 (as for today)

● Actively developed

Realtime application > processing requests● A web server works as a continuous process, doesn’t restart everytime a new

HTTP request is coming

● Can be stateless, but don’t have to be so

● We can get beyond the HTTP (WebSockets, HTTP2, SPDY and so on)

● Does a web server should only create response?

Fast prototyping and pivoting

Scalability● Horizontally scalable

● Since it runs a process it can be easily ran on multiple machines and load

balanced

● Thin runtime environment

One can build a desktop app● Electron

● NW.js

● APPjs

Many frontend frameworks

Isomorphic front- and backend● Common codebase both for the backend and the frontend

● No more redundant code!

WebSockets is a future of the Web (IMO)

Node native extensionsOne can write native modules/extensions to node.js (C/C++/Objective-C)

One can run it even on a coffee machine

<

How should I start?

Read some bookshttps://github.com/getify/You-Dont-Know-JS

Read some bookshttp://shop.oreilly.com/product/9780596517748.do

Read some bookshttps://www.manning.com/books/secrets-of-the-jav

ascript-ninja

Subscribe to some blogs/feeds● http://www.echojs.com/

● https://davidwalsh.name/

● http://jstherightway.org/

● https://www.sitepoint.com/

● https://medium.com/@dan_abramov

● http://javascriptweekly.com

Choose some framework

Play around and bring your ideas to life!

Come to the next #devduck!

top related