SlideShare a Scribd company logo
Marko Heijnen CODEKITCHEN
Node.js to the rescue

Let Node.js do things when WordPress/PHP isn’t enough
Marko Heijnen
• Founder of CodeKitchen
• Lead developer of GlotPress
• Core contributor for
WordPress
• Plugin developer
• Organizer for WordCamp
Belgrade 2015
• Technologist
Why something else?
Yes, you can build almost
everything in WordPress
But is that the smart
thing to do?
Can you trust on WordPress
to be always stable?
This summer I started moving
things away from WordPress
WP Central
WP Central
• Showing download history
• Showing version usage history
• List all locales and their current state (need update)
• Showing contributors data (currently API only)
• Collects history of locale progress
• Getting checksums for plugins & themes
How it works
• A lot of data handling by wp_remote_get
• Scrapping profiles.WordPress.org to read data
• Multiple API calls to api.WordPress.org
• Combine data so it can be presented
The problem
• Most things happened through WP Cron
• Some things happens on the front end
• Resulting a load on the webserver that could and
should be prevented
New server setup
Loadbalancer
Memcached
Elasticsearch
MariaDB
New server setup
Micro
services
Webserver 1
Webserver 2
Thumbor
Public Private
Service server
• MariaDB as database
• Memcached as object cache
• Moving to Redis when the PHP7 version is out
• Elasticsearch to make search better/faster
The microservices server
• Handles all cronjobs for the network site
• Node.js services running for WP Central
• Like getting checksums for plugins/themes
• Soon merging other WP cronjob calls for getting
all the stats
Microservices
Microservices
• Microservices are small, autonomous services that
work together
• Small, and Focused on Doing One Thing Well
Benefits
• Different services can use different programming
languages
• High level separation
• If WordPress breaks, the services still keep running
• Ease of Deployment
• Scale services that require more resources
Benefits
• In general they have an (REST) API
• Reusable
• Other microservices could call the service to run a
task
Node.js
What is Node.js
• JavaScript platform
• Uses an event-driven, non-blocking I/O model
• Lightweight and efficient
• Ideal for real time application
• Lot’s of modules you can use
• Manage with NPM - https://www.npmjs.org
Why to use it
• Internal webserver
• No configuration needed outside it’s code base
• You could use nginx as a proxy but not needed
• You get what you see approach
Who is using it
• Netflix
Need to know modules
• Express / Restify -> Webserver
• Socket.io -> Real time
• Request -> Doing internet requests
• async -> async calls with callback
• mysql -> MySQL driver with Pool support
• node-cmd -> Command line
Checksums for
plugins/themes
What is does
• Request checksum of a certain version from a
plugin or theme
• Download the zip and unzips it.
• Reads it in memory and get the checksum per
entry
• After everything is retrieved stores it in MySQL
Modules used
• Build in modules

FS

Crypto
• NPM Modules

Express

MySQL

Request

Yauzl for unzipping
• And build a little queue class
Calling the API
• http://wpcentral.io/api/checksums/plugin/tabify-
edit-screen/0.8.3 (REST API)
• Calls nginx by IP (10.10.10.10) which handles as a
fallback when the node.js application is down
• nginx calls then internally the node.js application
like proxy_pass http://127.0.0.1:8080
API calls
• /plugin/:slug/:version

http://10.10.10.10/checksums/plugin/:slug/:version 



http://wpcentral.io/api/checksums/plugin/tabify-
edit-screen/0.8.3
• /theme/:slug/:version

http://10.10.10.10/checksums/theme/:slug/:version



http://wpcentral.io/api/checksums/theme/
twentyfourteen/1.2
nginx rules
error_page 404 @404;

error_page 500 @500;

error_page 502 @502;
location @404 {

internal;

add_header Content-Type application/json always;

return 404 '{ "status": "Route Not Found" }';

}
return 500 '{ "status": "Service is down" }';

return 502 '{ "status": "Service is down" }';
Going over the code
Basic setup
// set variables for environment
var express = require('express'),
app = express(),
mysql = require('mysql'),
request = require('request'),
fs = require('fs'),
crypto = require('crypto'),
yauzl = require("yauzl");
MySQL connection
var pool = mysql.createPool({
connectionLimit : 10,
host : ’10.10.10.11’,
user : 'checksums',
password : 'checksums',
database : 'checksums'
});
pool.on('enqueue', function () {
log_error('Waiting for available connection slot');
});
Server
app.listen(4000);
app.get( '/plugin/:slug/:version', function(req, res) {
if ( ! queue.add( 'plugin', req.params.slug,
req.params.version, res ) ) {
res.json({
'success': false,
'error': 'Generating checksums’
});
}
});
Server 404
app.use(function(req, res, next) {
res.status(404).json({
'success': false,
'error': "Route doesn;'t exist”
});
});
Lets check the rest
Starting the server
• The default way is: node server.js
• The production server way could be:

pm2 start server.js -u www-data --name “Cool service”
The new situation
The new situation
• No more unneeded logic in WordPress
• WordPress simple pipes the calls
• Small services that replacing it
• APIs can easily be reused
• Pushing new updates becomes easier
• Currently no caching but easily added
Other things you could
use node.js for
See my presentation:

Extending WordPress as a pro
Describing an idea of using Socket.io with WordPress
Other ideas
• Scheduling tasks or url
calls
• Build a central cache
point for external
sources like getting
tweets
• Real time support
• git2svn sync
• Backup service
• Real time logger
• Perform heavy tasks
Thank you for
listening
Questions?
@markoheijnen
markoheijnen.com



codekitchen.eu
Ad

More Related Content

What's hot (20)

Bring api manager into your stack
Bring api manager into your stackBring api manager into your stack
Bring api manager into your stack
ColdFusionConference
 
Realtime with websockets
Realtime with websocketsRealtime with websockets
Realtime with websockets
ColdFusionConference
 
Hidden gems in cf2016
Hidden gems in cf2016Hidden gems in cf2016
Hidden gems in cf2016
ColdFusionConference
 
Command box
Command boxCommand box
Command box
ColdFusionConference
 
Securing applications
Securing applicationsSecuring applications
Securing applications
ColdFusionConference
 
Kickstart Jpa
Kickstart JpaKickstart Jpa
Kickstart Jpa
Max Andersen
 
Decoupled Architecture and WordPress
Decoupled Architecture and WordPressDecoupled Architecture and WordPress
Decoupled Architecture and WordPress
Pantheon
 
BP-7 Share Customization Best Practices
BP-7 Share Customization Best PracticesBP-7 Share Customization Best Practices
BP-7 Share Customization Best Practices
Alfresco Software
 
Workflows and Digital Signatures
Workflows and Digital SignaturesWorkflows and Digital Signatures
Workflows and Digital Signatures
ColdFusionConference
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git together
ColdFusionConference
 
Vaadin filtering table example
Vaadin filtering table exampleVaadin filtering table example
Vaadin filtering table example
leonardsiu
 
A look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architectureA look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architecture
Aimee Maree Forsstrom
 
Load Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusionLoad Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusion
ColdFusionConference
 
Locking Down CF Servers
Locking Down CF ServersLocking Down CF Servers
Locking Down CF Servers
ColdFusionConference
 
Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMS
ColdFusionConference
 
Introduction to vaadin
Introduction to vaadinIntroduction to vaadin
Introduction to vaadin
leonardsiu
 
How to Ensure You're Launching the Most Secure Website - Michael Tremante
How to Ensure You're Launching the Most Secure Website - Michael TremanteHow to Ensure You're Launching the Most Secure Website - Michael Tremante
How to Ensure You're Launching the Most Secure Website - Michael Tremante
WP Engine
 
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalBuilding modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Alessandro Pilotti
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
Stacy London
 
Performance tuning of Websites
Performance tuning of WebsitesPerformance tuning of Websites
Performance tuning of Websites
muHive Technologies
 
Decoupled Architecture and WordPress
Decoupled Architecture and WordPressDecoupled Architecture and WordPress
Decoupled Architecture and WordPress
Pantheon
 
BP-7 Share Customization Best Practices
BP-7 Share Customization Best PracticesBP-7 Share Customization Best Practices
BP-7 Share Customization Best Practices
Alfresco Software
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git together
ColdFusionConference
 
Vaadin filtering table example
Vaadin filtering table exampleVaadin filtering table example
Vaadin filtering table example
leonardsiu
 
A look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architectureA look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architecture
Aimee Maree Forsstrom
 
Load Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusionLoad Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusion
ColdFusionConference
 
Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMS
ColdFusionConference
 
Introduction to vaadin
Introduction to vaadinIntroduction to vaadin
Introduction to vaadin
leonardsiu
 
How to Ensure You're Launching the Most Secure Website - Michael Tremante
How to Ensure You're Launching the Most Secure Website - Michael TremanteHow to Ensure You're Launching the Most Secure Website - Michael Tremante
How to Ensure You're Launching the Most Secure Website - Michael Tremante
WP Engine
 
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalBuilding modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Alessandro Pilotti
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
Stacy London
 

Viewers also liked (20)

Wc norrkoping-2015
Wc norrkoping-2015Wc norrkoping-2015
Wc norrkoping-2015
pelmered
 
Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!
Konstantin Obenland
 
Introducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystemIntroducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystem
GGDBologna
 
how to not design like a developer
how to not design like a developerhow to not design like a developer
how to not design like a developer
tracy apps
 
WordPress for Designers
WordPress for DesignersWordPress for Designers
WordPress for Designers
Red8 Interactive
 
Design in WordPress: Three files, unlimited layouts #wcstl
Design in WordPress: Three files, unlimited layouts #wcstlDesign in WordPress: Three files, unlimited layouts #wcstl
Design in WordPress: Three files, unlimited layouts #wcstl
WordCamp
 
SEO para Wordpress (WordCamp Salvador)
SEO para Wordpress (WordCamp Salvador)SEO para Wordpress (WordCamp Salvador)
SEO para Wordpress (WordCamp Salvador)
Ian Castro
 
Build your site tonight, be blogging tomorrow
Build your site tonight, be blogging tomorrowBuild your site tonight, be blogging tomorrow
Build your site tonight, be blogging tomorrow
Warren Denley
 
WordPress in a Time of Crisis
WordPress in a Time of CrisisWordPress in a Time of Crisis
WordPress in a Time of Crisis
Michelle Amaral
 
Wordpress Plugin Development Practices
Wordpress Plugin Development PracticesWordpress Plugin Development Practices
Wordpress Plugin Development Practices
serversideup
 
Open Source Entrepreneurship
Open Source EntrepreneurshipOpen Source Entrepreneurship
Open Source Entrepreneurship
Jimmy Rosén
 
My first 3 months working with word press
My first 3 months working with word pressMy first 3 months working with word press
My first 3 months working with word press
Noe Lopez
 
Customize your theme using css
Customize your theme using cssCustomize your theme using css
Customize your theme using css
Michael Arestad
 
Leveraging Wordpress for an Ecommerce Website
Leveraging Wordpress for an Ecommerce WebsiteLeveraging Wordpress for an Ecommerce Website
Leveraging Wordpress for an Ecommerce Website
Will Hanke
 
Customizing the custom loop wordcamp 2012-jeff
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeff
Alexander Sapountzis
 
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Evan Mullins
 
Can You Go Commercial
Can You Go CommercialCan You Go Commercial
Can You Go Commercial
garthkoyle
 
Questions you’re too afraid to ask
Questions you’re too afraid to askQuestions you’re too afraid to ask
Questions you’re too afraid to ask
Eric Mann
 
Gerenciamento de sites/blogs com o WordPress 3.4
Gerenciamento de sites/blogs com o WordPress 3.4Gerenciamento de sites/blogs com o WordPress 3.4
Gerenciamento de sites/blogs com o WordPress 3.4
Mayara Alanna Pereira Martins
 
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
Sergio Costa
 
Wc norrkoping-2015
Wc norrkoping-2015Wc norrkoping-2015
Wc norrkoping-2015
pelmered
 
Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!
Konstantin Obenland
 
Introducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystemIntroducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystem
GGDBologna
 
how to not design like a developer
how to not design like a developerhow to not design like a developer
how to not design like a developer
tracy apps
 
Design in WordPress: Three files, unlimited layouts #wcstl
Design in WordPress: Three files, unlimited layouts #wcstlDesign in WordPress: Three files, unlimited layouts #wcstl
Design in WordPress: Three files, unlimited layouts #wcstl
WordCamp
 
SEO para Wordpress (WordCamp Salvador)
SEO para Wordpress (WordCamp Salvador)SEO para Wordpress (WordCamp Salvador)
SEO para Wordpress (WordCamp Salvador)
Ian Castro
 
Build your site tonight, be blogging tomorrow
Build your site tonight, be blogging tomorrowBuild your site tonight, be blogging tomorrow
Build your site tonight, be blogging tomorrow
Warren Denley
 
WordPress in a Time of Crisis
WordPress in a Time of CrisisWordPress in a Time of Crisis
WordPress in a Time of Crisis
Michelle Amaral
 
Wordpress Plugin Development Practices
Wordpress Plugin Development PracticesWordpress Plugin Development Practices
Wordpress Plugin Development Practices
serversideup
 
Open Source Entrepreneurship
Open Source EntrepreneurshipOpen Source Entrepreneurship
Open Source Entrepreneurship
Jimmy Rosén
 
My first 3 months working with word press
My first 3 months working with word pressMy first 3 months working with word press
My first 3 months working with word press
Noe Lopez
 
Customize your theme using css
Customize your theme using cssCustomize your theme using css
Customize your theme using css
Michael Arestad
 
Leveraging Wordpress for an Ecommerce Website
Leveraging Wordpress for an Ecommerce WebsiteLeveraging Wordpress for an Ecommerce Website
Leveraging Wordpress for an Ecommerce Website
Will Hanke
 
Customizing the custom loop wordcamp 2012-jeff
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeff
Alexander Sapountzis
 
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Evan Mullins
 
Can You Go Commercial
Can You Go CommercialCan You Go Commercial
Can You Go Commercial
garthkoyle
 
Questions you’re too afraid to ask
Questions you’re too afraid to askQuestions you’re too afraid to ask
Questions you’re too afraid to ask
Eric Mann
 
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
Sergio Costa
 
Ad

Similar to Node.js to the rescue (20)

Extending WordPress as a pro
Extending WordPress as a proExtending WordPress as a pro
Extending WordPress as a pro
Marko Heijnen
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
ssuser35fdf2
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
Stuart (Pid) Williams
 
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - RedmondBuilding APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Rick G. Garibay
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
Christian Joudrey
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
.NET Cloud-Native Bootcamp
.NET Cloud-Native Bootcamp.NET Cloud-Native Bootcamp
.NET Cloud-Native Bootcamp
VMware Tanzu
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Nathen Harvey
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
DevOps <3 node.js
DevOps <3 node.jsDevOps <3 node.js
DevOps <3 node.js
Jeff Miccolis
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with Faye
Matjaž Lipuš
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
Vagif Abilov
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
Khaled Mosharraf
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
Alex Thissen
 
[Struyf] Automate Your Tasks With Azure Functions
[Struyf] Automate Your Tasks With Azure Functions[Struyf] Automate Your Tasks With Azure Functions
[Struyf] Automate Your Tasks With Azure Functions
European Collaboration Summit
 
Apigility-powered API's on IBM i
Apigility-powered API's on IBM iApigility-powered API's on IBM i
Apigility-powered API's on IBM i
chukShirley
 
Deep dive into share point framework webparts
Deep dive into share point framework webpartsDeep dive into share point framework webparts
Deep dive into share point framework webparts
Prabhu Nehru
 
Hello world - intro to node js
Hello world - intro to node jsHello world - intro to node js
Hello world - intro to node js
Refresh Annapolis Valley
 
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and AngularEscaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Mark Leusink
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Ryan Cuprak
 
Extending WordPress as a pro
Extending WordPress as a proExtending WordPress as a pro
Extending WordPress as a pro
Marko Heijnen
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
ssuser35fdf2
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
Stuart (Pid) Williams
 
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - RedmondBuilding APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Rick G. Garibay
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
Christian Joudrey
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
.NET Cloud-Native Bootcamp
.NET Cloud-Native Bootcamp.NET Cloud-Native Bootcamp
.NET Cloud-Native Bootcamp
VMware Tanzu
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Nathen Harvey
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
DevOps <3 node.js
DevOps <3 node.jsDevOps <3 node.js
DevOps <3 node.js
Jeff Miccolis
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with Faye
Matjaž Lipuš
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
Vagif Abilov
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
Alex Thissen
 
Apigility-powered API's on IBM i
Apigility-powered API's on IBM iApigility-powered API's on IBM i
Apigility-powered API's on IBM i
chukShirley
 
Deep dive into share point framework webparts
Deep dive into share point framework webpartsDeep dive into share point framework webparts
Deep dive into share point framework webparts
Prabhu Nehru
 
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and AngularEscaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Mark Leusink
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Ryan Cuprak
 
Ad

More from Marko Heijnen (20)

Custom coded projects
Custom coded projectsCustom coded projects
Custom coded projects
Marko Heijnen
 
Security, more important than ever!
Security, more important than ever!Security, more important than ever!
Security, more important than ever!
Marko Heijnen
 
My Contributor Story
My Contributor StoryMy Contributor Story
My Contributor Story
Marko Heijnen
 
WooCommerce & Apple TV
WooCommerce & Apple TVWooCommerce & Apple TV
WooCommerce & Apple TV
Marko Heijnen
 
The moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp SofiaThe moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp Sofia
Marko Heijnen
 
Mijn site beveiliging
Mijn site beveiligingMijn site beveiliging
Mijn site beveiliging
Marko Heijnen
 
The moment my site got hacked
The moment my site got hackedThe moment my site got hacked
The moment my site got hacked
Marko Heijnen
 
My complicated WordPress site
My complicated WordPress siteMy complicated WordPress site
My complicated WordPress site
Marko Heijnen
 
Protecting your site by detection
Protecting your site by detectionProtecting your site by detection
Protecting your site by detection
Marko Heijnen
 
GlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.orgGlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.org
Marko Heijnen
 
Writing clean and maintainable code
Writing clean and maintainable codeWriting clean and maintainable code
Writing clean and maintainable code
Marko Heijnen
 
Let's create a multilingual site in WordPress
Let's create a multilingual site in WordPressLet's create a multilingual site in WordPress
Let's create a multilingual site in WordPress
Marko Heijnen
 
Bootstrapping your plugin
Bootstrapping your pluginBootstrapping your plugin
Bootstrapping your plugin
Marko Heijnen
 
The development and future of GlotPress
The development and future of GlotPressThe development and future of GlotPress
The development and future of GlotPress
Marko Heijnen
 
Why Javascript matters
Why Javascript mattersWhy Javascript matters
Why Javascript matters
Marko Heijnen
 
The code history of WordPress
The code history of WordPressThe code history of WordPress
The code history of WordPress
Marko Heijnen
 
Building plugins like a pro
Building plugins like a proBuilding plugins like a pro
Building plugins like a pro
Marko Heijnen
 
Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013
Marko Heijnen
 
Dealing with media
Dealing with mediaDealing with media
Dealing with media
Marko Heijnen
 
The awesome things you can do with images inside WordPress
The awesome things you can do with images inside WordPressThe awesome things you can do with images inside WordPress
The awesome things you can do with images inside WordPress
Marko Heijnen
 
Custom coded projects
Custom coded projectsCustom coded projects
Custom coded projects
Marko Heijnen
 
Security, more important than ever!
Security, more important than ever!Security, more important than ever!
Security, more important than ever!
Marko Heijnen
 
My Contributor Story
My Contributor StoryMy Contributor Story
My Contributor Story
Marko Heijnen
 
WooCommerce & Apple TV
WooCommerce & Apple TVWooCommerce & Apple TV
WooCommerce & Apple TV
Marko Heijnen
 
The moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp SofiaThe moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp Sofia
Marko Heijnen
 
Mijn site beveiliging
Mijn site beveiligingMijn site beveiliging
Mijn site beveiliging
Marko Heijnen
 
The moment my site got hacked
The moment my site got hackedThe moment my site got hacked
The moment my site got hacked
Marko Heijnen
 
My complicated WordPress site
My complicated WordPress siteMy complicated WordPress site
My complicated WordPress site
Marko Heijnen
 
Protecting your site by detection
Protecting your site by detectionProtecting your site by detection
Protecting your site by detection
Marko Heijnen
 
GlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.orgGlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.org
Marko Heijnen
 
Writing clean and maintainable code
Writing clean and maintainable codeWriting clean and maintainable code
Writing clean and maintainable code
Marko Heijnen
 
Let's create a multilingual site in WordPress
Let's create a multilingual site in WordPressLet's create a multilingual site in WordPress
Let's create a multilingual site in WordPress
Marko Heijnen
 
Bootstrapping your plugin
Bootstrapping your pluginBootstrapping your plugin
Bootstrapping your plugin
Marko Heijnen
 
The development and future of GlotPress
The development and future of GlotPressThe development and future of GlotPress
The development and future of GlotPress
Marko Heijnen
 
Why Javascript matters
Why Javascript mattersWhy Javascript matters
Why Javascript matters
Marko Heijnen
 
The code history of WordPress
The code history of WordPressThe code history of WordPress
The code history of WordPress
Marko Heijnen
 
Building plugins like a pro
Building plugins like a proBuilding plugins like a pro
Building plugins like a pro
Marko Heijnen
 
Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013
Marko Heijnen
 
The awesome things you can do with images inside WordPress
The awesome things you can do with images inside WordPressThe awesome things you can do with images inside WordPress
The awesome things you can do with images inside WordPress
Marko Heijnen
 

Recently uploaded (20)

Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 

Node.js to the rescue

  • 1. Marko Heijnen CODEKITCHEN Node.js to the rescue
 Let Node.js do things when WordPress/PHP isn’t enough
  • 2. Marko Heijnen • Founder of CodeKitchen • Lead developer of GlotPress • Core contributor for WordPress • Plugin developer • Organizer for WordCamp Belgrade 2015 • Technologist
  • 4. Yes, you can build almost everything in WordPress
  • 5. But is that the smart thing to do?
  • 6. Can you trust on WordPress to be always stable?
  • 7. This summer I started moving things away from WordPress
  • 9. WP Central • Showing download history • Showing version usage history • List all locales and their current state (need update) • Showing contributors data (currently API only) • Collects history of locale progress • Getting checksums for plugins & themes
  • 10. How it works • A lot of data handling by wp_remote_get • Scrapping profiles.WordPress.org to read data • Multiple API calls to api.WordPress.org • Combine data so it can be presented
  • 11. The problem • Most things happened through WP Cron • Some things happens on the front end • Resulting a load on the webserver that could and should be prevented
  • 14. Service server • MariaDB as database • Memcached as object cache • Moving to Redis when the PHP7 version is out • Elasticsearch to make search better/faster
  • 15. The microservices server • Handles all cronjobs for the network site • Node.js services running for WP Central • Like getting checksums for plugins/themes • Soon merging other WP cronjob calls for getting all the stats
  • 17. Microservices • Microservices are small, autonomous services that work together • Small, and Focused on Doing One Thing Well
  • 18. Benefits • Different services can use different programming languages • High level separation • If WordPress breaks, the services still keep running • Ease of Deployment • Scale services that require more resources
  • 19. Benefits • In general they have an (REST) API • Reusable • Other microservices could call the service to run a task
  • 21. What is Node.js • JavaScript platform • Uses an event-driven, non-blocking I/O model • Lightweight and efficient • Ideal for real time application • Lot’s of modules you can use • Manage with NPM - https://www.npmjs.org
  • 22. Why to use it • Internal webserver • No configuration needed outside it’s code base • You could use nginx as a proxy but not needed • You get what you see approach
  • 23. Who is using it • Netflix
  • 24. Need to know modules • Express / Restify -> Webserver • Socket.io -> Real time • Request -> Doing internet requests • async -> async calls with callback • mysql -> MySQL driver with Pool support • node-cmd -> Command line
  • 26. What is does • Request checksum of a certain version from a plugin or theme • Download the zip and unzips it. • Reads it in memory and get the checksum per entry • After everything is retrieved stores it in MySQL
  • 27. Modules used • Build in modules
 FS
 Crypto • NPM Modules
 Express
 MySQL
 Request
 Yauzl for unzipping • And build a little queue class
  • 28. Calling the API • http://wpcentral.io/api/checksums/plugin/tabify- edit-screen/0.8.3 (REST API) • Calls nginx by IP (10.10.10.10) which handles as a fallback when the node.js application is down • nginx calls then internally the node.js application like proxy_pass http://127.0.0.1:8080
  • 29. API calls • /plugin/:slug/:version
 http://10.10.10.10/checksums/plugin/:slug/:version 
 
 http://wpcentral.io/api/checksums/plugin/tabify- edit-screen/0.8.3 • /theme/:slug/:version
 http://10.10.10.10/checksums/theme/:slug/:version
 
 http://wpcentral.io/api/checksums/theme/ twentyfourteen/1.2
  • 30. nginx rules error_page 404 @404;
 error_page 500 @500;
 error_page 502 @502; location @404 {
 internal;
 add_header Content-Type application/json always;
 return 404 '{ "status": "Route Not Found" }';
 } return 500 '{ "status": "Service is down" }';
 return 502 '{ "status": "Service is down" }';
  • 32. Basic setup // set variables for environment var express = require('express'), app = express(), mysql = require('mysql'), request = require('request'), fs = require('fs'), crypto = require('crypto'), yauzl = require("yauzl");
  • 33. MySQL connection var pool = mysql.createPool({ connectionLimit : 10, host : ’10.10.10.11’, user : 'checksums', password : 'checksums', database : 'checksums' }); pool.on('enqueue', function () { log_error('Waiting for available connection slot'); });
  • 34. Server app.listen(4000); app.get( '/plugin/:slug/:version', function(req, res) { if ( ! queue.add( 'plugin', req.params.slug, req.params.version, res ) ) { res.json({ 'success': false, 'error': 'Generating checksums’ }); } });
  • 35. Server 404 app.use(function(req, res, next) { res.status(404).json({ 'success': false, 'error': "Route doesn;'t exist” }); });
  • 37. Starting the server • The default way is: node server.js • The production server way could be:
 pm2 start server.js -u www-data --name “Cool service”
  • 39. The new situation • No more unneeded logic in WordPress • WordPress simple pipes the calls • Small services that replacing it • APIs can easily be reused • Pushing new updates becomes easier • Currently no caching but easily added
  • 40. Other things you could use node.js for
  • 41. See my presentation:
 Extending WordPress as a pro Describing an idea of using Socket.io with WordPress
  • 42. Other ideas • Scheduling tasks or url calls • Build a central cache point for external sources like getting tweets • Real time support • git2svn sync • Backup service • Real time logger • Perform heavy tasks