s h a k ra s a nd h o t s to n e t h e ra py ( s h s t )€¦ · java -xmx4g -xms4g -jar app.jar::...
TRANSCRIPT
Shakras and Hot Stone Therapy (SHST)Shakras and Hot Stone Therapy (SHST)
Modern techniques for relaxation using ancient methodsModern techniques for relaxation using ancient methods
(a hands-on approach)(a hands-on approach)
1 . 1
Server Architectures with NodeServer Architectures with Node
Why should the browser folk have all the fun?Why should the browser folk have all the fun?
1 . 2
Your friendly presenterYour friendly presenter
Jeffrey [email protected], Chariot SolutionsSomewhat Recent Javascript Convert
1 . 3
Javascript Convert?Javascript Convert?
1 . 4
Javascript Convert?Javascript Convert?
Actually, yesActually, yes
1 . 4
However, there's beauty in thereHowever, there's beauty in there
1 . 5
However, there's beauty in thereHowever, there's beauty in there
This may take a bit of time to �nd.This may take a bit of time to �nd.
1 . 5
E�cient use of resources makes me happy.E�cient use of resources makes me happy.
2 . 1
E�cient use of resources makes me happy.E�cient use of resources makes me happy.
(hapi?)
2 . 1
This thing is This thing is thinthin
2 . 2
Customer production server from pm2:
$ pm2 status │ SERVER (PROD) │ online | 12D │ 0% │ 148.7 MB |
2 . 3
Customer production server from pm2:
12 days of uptime12 days of uptime
$ pm2 status │ SERVER (PROD) │ online | 12D │ 0% │ 148.7 MB |
2 . 3
Customer production server from pm2:
12 days of uptime12 days of uptime
150MB of RAM!150MB of RAM!
$ pm2 status │ SERVER (PROD) │ online | 12D │ 0% │ 148.7 MB |
2 . 3
java -Xmx4G -Xms4G -jar app.jar
:: Spring Boot :: (v2.0.3.RELEASE) Started TestApp in 24.351 seconds (JVM running for 24.811)
2 . 4
Single threadedSingle threaded
2 . 5
Code isomorphism between client and serverCode isomorphism between client and server
If you use JS on the client...If you use JS on the client...
2 . 6
Fun to write, to be honestFun to write, to be honest
2 . 7
JS is a gateway drug to LambdaJS is a gateway drug to Lambda
2 . 8
Node architecture makes me happyNode architecture makes me happy
3 . 1
Node architecture makes me happyNode architecture makes me happy
(hapi?)
3 . 1
Node was born from two neat pieces ofNode was born from two neat pieces oftechnologytechnology
3 . 2
Node was born from two neat pieces ofNode was born from two neat pieces oftechnologytechnology
libuvlibuv
3 . 2
Node was born from two neat pieces ofNode was born from two neat pieces oftechnologytechnology
libuvlibuv
v8v8
3 . 2
3 . 3
3 . 4
v8v8 & & shakrashakra
3 . 5
libuvlibuv
3 . 6
Only a matter of timeOnly a matter of time
3 . 7
What, exactly, is it good for?What, exactly, is it good for?
3 . 8
IOIO
3 . 9
IOIO
Like, Like, tonstons of IO of IO
3 . 9
3 . 10
Try not to do too muchTry not to do too much
All CPU use on node is crimethinkAll CPU use on node is crimethink
Get in, get outGet in, get out
3 . 11
A humorous vingette...A humorous vingette...
3 . 12
bcrypt(3)bcrypt(3)!!!!!!!!!!
3 . 13
WARNING:WARNING:
Handrails are not availableHandrails are not available
3 . 14
There really is only one real method in nodeThere really is only one real method in nodethat matters.that matters.
3 . 15
There really is only one real method in nodeThere really is only one real method in nodethat matters.that matters.
on()on()
3 . 15
3 . 16
Looks familiar?Looks familiar?
server.on('request', (req, res) => { // node HTTP server }) observer.subscribe((x) => { // Angular HttpClient })
3 . 17
The fundamental unit of javascript is theThe fundamental unit of javascript is thecontinuationcontinuation..
Javascript is a Javascript is a continuation orientedcontinuation orientedlanguage.language.
3 . 18
whenItIsDone(thing, (result) => { doSomethingElse(result) })
3 . 19
const fs = require('fs') fs.readFile('./foo.txt', 'utf8', (err, contents) => { console.log(contents) });
3 . 20
The The continuationcontinuation is a lambda is a lambda
3 . 21
The The continuationcontinuation is a lambda is a lambda
It executes later.It executes later.
3 . 21
The The continuationcontinuation is a lambda is a lambda
It executes later.It executes later.
You can never get here from there.You can never get here from there.
3 . 21
(err, contents) => { console.log(contents) });
3 . 22
fs.readFile('./foo.txt', 'utf8', (err, contents) => { console.log(contents) }); fs.readFile('./bar.txt', 'utf8', (err, contents) => { console.log(contents) });
3 . 23
This is the beauty of nodejsThis is the beauty of nodejs
Handle your result Handle your result
3 . 24
This is the beauty of nodejsThis is the beauty of nodejs
Handle your result Handle your result laterlater
3 . 24
Man, it can get ugly fastMan, it can get ugly fast
4 . 1
const fs = require('fs') const dns = require('net') fs.readFile('./foo.txt', 'utf8', (err, contents) => { fs.writeFile('./bar.txt', 'utf8', (err, contents) => { dns.lookup(contents, (err, address, family) => { console.log(address) }) }) })
4 . 2
do(foo, bar => { some(bar, baz => { thing(baz, quux => { complex(quux, quuz => { eventually(quuz, waldo => { go(waldo, fred => { crazy(fred, thud => { console.log(thud) }) }) }) }) }) }) })
4 . 3
Promises are syntactic sugarPromises are syntactic sugar
4 . 4
do(foo) .then(bar => { some(bar) }).then(baz => { thing(baz) }).then(quux => { complex(quux) }).then(quuz => { eventually(quuz) }).then(waldo => { go(waldo) }).then(fred => { crazy(fred) }).then(thud => { console.log(thud)
4 . 5
asyncasync / / awaitawait are the new hotness are the new hotness
4 . 6
try{ const bar = await do(foo) const baz = await some(bar) const quux = await thing(baz) const quuz = await complex(quux) const waldo = await eventually(quuz) const fred = await go(waldo) const thud = await crazy(fred) console.log(thud) }catch(err){ // whoops }
4 . 7
const p = do(foo); const bar = await p;
4 . 8
const util = require('util') const readFileAsync = util.promisify(fs.readFile) const contents = await readFileAsync('./foo.txt', 'utf8')
4 . 9
4 . 10
4 . 11
const f = (a, b) => { return a + b } const p = f('a', ?) assert(p('b') === 'ab')
4 . 12
Let's do some actual Let's do some actual workwork..
5 . 1
REST serversREST servers
ExpressHAPIRestifyLoopbackSails... probably a baker's dozen more by now
5 . 2
Express.js is the gold standardExpress.js is the gold standard
Does whatcha needDoes whatcha need
5 . 3
const express = require('express') const app = express() const port = 80 app.get('/', (req, res) => res.send('Hello World!')) app.listen(port, () => console.log(`Example app listening on por
5 . 4
C'mon get HAPIC'mon get HAPI
5 . 5
[email protected]:chariotspaday/[email protected]:chariotspaday/server.git
5 . 6
Things to likeThings to like
In this desolate wasteland of In this desolate wasteland of ~0.0.9~0.0.9
5 . 7
Vibrant plugins, easy API to write your ownVibrant plugins, easy API to write your own
goodboomnescon�dencepoopbellblipp
5 . 8
server.route({ method: 'GET', path: '/', handler: function (request, h) { return 'Hello!' } })
5 . 9
hapi ❤ joihapi ❤ joi
const session = joi.object().keys({ id: joi.number().integer().min(1).required(), name: joi.string().trim(true).min(1).required(), date: joi.string().trim(true).isoDate().required() })
5 . 10
method: 'GET', options: { tags: ['api'], description: 'Gets all subscriptions for a session', path: '/session/{id}/subscriptions', validate: { params: { id: joi.number().integer().min(1) } },
5 . 11
response: { options: { abortEarly: false }, sample: 100, schema: joi.array().items(joiSchemas.registration) }
5 . 12
"/api/session": { "get": { "responses": { "default": { "description": "", "schema": { "type": "array", "items": { "$ref": "#/definitions/IdNameDateModel" } } } }, "produces": ["application/json"], "tags": ["api"],
5 . 13
5 . 14
Stupid node tricks with hapi, express, andStupid node tricks with hapi, express, andwebsocketswebsockets
5 . 15
const hapi = require('hapi') const ws = require('ws') const server = new hapi.Server({port: 8000}) const listener = server.listener const wss = new WebSocket.Server({ server: listener, path: '/api/chat' }) await server.start()
5 . 16
this._removeListeners = addListeners(this._server, { listening: this.emit.bind(this, 'listening'), error: this.emit.bind(this, 'error'), upgrade: (req, socket, head) => { this.handleUpgrade(req, socket, head, (ws) => { this.emit('connection', ws, req); }); } });
5 . 17
server.events.on('log', (event, tags) => { server.events.on('request', (request, event, tags) => { server.events.on('response', (request) => {
5 . 18
Takeaway (whew!)Takeaway (whew!)
Understand on()Grok continuations, how code moves through nodeNever eat CPU.Use cool language featuresBe Javascripty on the server
6