{"id":13455212,"url":"https://github.com/azat-co/you-dont-know-node","last_synced_at":"2025-05-15T20:03:04.127Z","repository":{"id":45902317,"uuid":"43770860","full_name":"azat-co/you-dont-know-node","owner":"azat-co","description":"You Don't Know Node.js","archived":false,"fork":false,"pushed_at":"2018-11-27T09:04:15.000Z","size":139015,"stargazers_count":1540,"open_issues_count":1,"forks_count":165,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-05-13T13:05:59.265Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://webapplog.com/you-dont-know-node/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azat-co.png","metadata":{"files":{"readme":"README-v1.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-06T18:39:43.000Z","updated_at":"2025-05-13T11:05:07.000Z","dependencies_parsed_at":"2022-08-12T12:40:11.460Z","dependency_job_id":null,"html_url":"https://github.com/azat-co/you-dont-know-node","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-co%2Fyou-dont-know-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-co%2Fyou-dont-know-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-co%2Fyou-dont-know-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azat-co%2Fyou-dont-know-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azat-co","download_url":"https://codeload.github.com/azat-co/you-dont-know-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254010824,"owners_count":21998993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:01:02.485Z","updated_at":"2025-05-15T20:03:02.187Z","avatar_url":"https://github.com/azat-co.png","language":"Python","funding_links":[],"categories":["Resources","Python","Web Development","NodeJS","Tutorials","Packages","资源"],"sub_categories":["Tutorials","教程"],"readme":"footer: © Node.University, 2016\nslidenumbers: true\n\n\n![](images/you-dk-node-course-cover-v1.png)\n\n---\n\n# You Don't Know Node\n## Quick Intro to 5 Core Features\n\n---\n\n# Code along and take notes\n\n---\n\n# Slides \u0026 Code :page_facing_up: 💻\n\nEverything: \u003chttps://github.com/azat-co/you-dont-know-node\u003e\n\nor\n\njust PDF: \u003chttp://bit.ly/1VJWpQK\u003e\n\n---\n\n# Better Apps—Better Life\n\n^Big idea: Node has some cool core features. Node is everywhere. What if the world can be a better place if more developers master Node?\n\n---\n\n# About Presenter\n\n---\n\n![inline](images/azats-books-covers.png)\n\n^Wrote and published 12 books not counting Korean, Chinese, Polish and Russian translations\n\n---\n\nAzat Mardan\n\n![inline](images/azat.jpeg)\n\nTwitter: @azat_co\nEmail: hi@azat.co\nBlog: webapplog.com\n\n---\n\n# About Presenter\n\n* Work: Technology Fellow at Capital One (kind of a big deal)\n* Experience: FDIC, NIH, DocuSign, HackReactor and Storify\n* Books: React Quickly, Practical Node.js, Pro Express.js, Express.js API and 8 others\n* Teach: [NodeProgram.com](http://NodeProgram.com)\n* Master of Science from University of Northern Virginia\n\n\n---\n\n# Capital One in Top 10 US Banks\n\n![inline](images/commercial.gif)\n\n---\n\n# Starting with basics: Why Use Node?\n\n---\n\n# Input/output is one of the most expensive type tasks (\u003eCPU) 💰\n\n---\n\n# Node has non-blocking I/O\n\n\n---\n\n![inline](images/non-blocking.png)\n\n^This allows processing other tasks while IO calls are unfinished like this\n^Nginx vs. Apache\n^Blocking I/O is expensive!\n\n\n---\n\n### Java Sleep\n\n```java\nSystem.out.println(\"Step: 1\");\nSystem.out.println(\"Step: 2\");\nThread.sleep(1000);\nSystem.out.println(\"Step: 3\");\n```\n\n\n\n---\n\n## Node \"Sleep\"\n\n```js\nconsole.log('Step: 1')\nsetTimeout(function () {\n  console.log('Step: 3')\n}, 1000)\nconsole.log('Step: 2')\n```\n\n---\n\n## Process Multiple Tasks\n\n```js\nconsole.log('Step: 1')\nsetTimeout(function () {\n  console.log('Step: 3')\n  // console.log('Step 5')\n}, 1000);\nconsole.log('Step: 2')\n// console.log('Step 4')\n```\n\n---\n\n# Blocking Web Server\n\n---\n\n![inline](images/threading_java.png)\n\n---\n\n![inline](images/coffeeshop-blocking.jpg)\n\n---\n\n# Non-Blocking Web Server\n\n---\n\n![inline](images/threading_node.png)\n\n^This is in contrast to today's more common concurrency model where OS threads are employed. Thread-based networking is relatively inefficient and very difficult to use. Furthermore, users of Node are free from worries of dead-locking the process --- there are no locks\n\n---\n\n![inline](images/coffeeshop-non-blocking.jpg)\n\n---\n\n# [Multi-threading] is the software equivalent of a nuclear device because if it is used incorrectly, it can blow up in your face.\n\n\u003chttp://blog.codinghorror.com/threading-concurrency-and-the-most-powerful-psychokinetic-explosive-in-the-univ\u003e\n\n---\n\n# Blocking systems have to be multi-threaded\n\n---\n\n# Node is single threaded... and that's good! 😄\n\n\n---\n\n\n## It's still possible to write blocking code in Node.js. :flushed:\n\n\n---\n\n# Blocking Node.js Code\n\n```js\n// blocking.js\nconsole.log('Step: 1')\nfor (var i = 1; i\u003c1000000000; i++) {\n  // This will take 100-1000ms\n}\nconsole.log('Step: 2')\n```\n\n---\n\n# Blocking Node.js Code\n\n```js\nvar fs = require('fs')\n\nvar contents = fs.readFileSync('accounts.txt','utf8')\nconsole.log(contents)\nconsole.log('Hello Ruby\\n')\n\nvar contents = fs.readFileSync('ips.txt','utf8')\nconsole.log(contents)\nconsole.log('Hello Node!')\n//accounts.txt-\u003eHello Ruby-\u003eips.txt-\u003eHello Node!\n```\n\n---\n\n# Non-Blocking Node.js Code\n\n```js\nvar fs = require('fs')\n\nfs.readFile('accounts.txt','utf8', function(error, contents){\n   console.log(contents)\n})\nconsole.log('Hello Ruby\\n')\n\nfs.readFile('ips.txt','utf8', function(error, contents){\n   console.log(contents)\n})\nconsole.log('Hello Node!')\n//Hello Ruby-\u003eHello Node-\u003e... accounts.txt-\u003eips.txt or ips.txt-\u003eaccounts.txt\n```\n\n---\n\n# Node *typically* is much faster than other platforms\n\n---\n\n# How many of you reach the performance limitations of apps built with blocking I/O systems?\n\n---\n\n# Probably not many\n\n---\n\n# My Fav Node Benefit\n\n---\n\n# JavaScript everywhere. One language to rule 'em all!\n\n---\n\n* Think faster\n* Reuse code\n* Learn quicker\n\n---\n\n# Most of Node is JavaScript\n\n* Array\n* String\n* Primitives\n* Functions\n* Objects\n\n---\n\n\n# Node !== Browser JavaScript\n\n---\n\n# How to create global variables (no `window` in Node), work with modules, get path to my script?\n\n---\n\n# `global` or `GLOBAL`\n\n---\n\n# It has properties!\n\n---\n\n\n# `global.__filename`\n# `global.__dirname`\n\n\n---\n\n\n# `global.module`\n# `global.require()`\n\n---\n\n# How do I...?\n\n* Access CLI input?\n* Get system info: OS, platform, memory usage, versions, etc.?\n* Read env vars (passwords!)?\n\n---\n\n# `global.process` or `process`\n\n---\n\n# `process.pid`\n# `process.versions`\n# `process.arch`\n\n---\n\n# `process.argv`\n\n---\n\n# `process.env`\n\n---\n\n\n# `process.uptime()`\n# `process.memoryUsage()`\n\n---\n\n# `process.cwd()`\n\n---\n\n# `process.exit()`\n# `process.kill()`\n\n---\n\n#  Who likes and understands callbacks? 🙋\n\n---\n\n\u003chttp://callbackhell.com\u003e\n\n```js\nfs.readdir(source, function (err, files) {\n  if (err) {\n    console.log('Error finding files: ' + err)\n  } else {\n    files.forEach(function (filename, fileIndex) {\n      console.log(filename)\n      gm(source + filename).size(function (err, values) {\n        if (err) {\n          console.log('Error identifying file size: ' + err)\n        } else {\n          console.log(filename + ' : ' + values)\n          aspect = (values.width / values.height)\n          widths.forEach(function (width, widthIndex) {\n            height = Math.round(width / aspect)\n            console.log('resizing ' + filename + 'to ' + height + 'x' + height)\n            this.resize(width, height).write(dest + 'w' + width + '_' + filename, function(err) {\n              if (err) console.log('Error writing file: ' + err)\n            })\n          }.bind(this))\n        }\n      })\n    })\n  }\n})\n```\n\n---\n\n\n## Callbacks are not very developmental scalable 😞\n\n---\n\n# Me When Working With Deeply Nested Callbacks\n\n![inline](images/tree_slam.gif)\n\n---\n\n# Events\n\nEvents are part of core and supported by most of the core modules while more advanced patterns such as promises, generators, async/await are not.\n\n\n---\n\n### Events == Node Observer Pattern\n\n* Subject\n* Observers (event listeners) on a subject\n* Event triggers\n\n---\n\n### Events\n\n```js\nvar events = require('events')\nvar emitter = new events.EventEmitter()\n```\n\n---\n\n### Events\n\nIn node.js an event can be described simply as a string with a corresponding callback.\n\n\n```js\nemitter.on('done', function(results) {\n  console.log('Done: ', results)\n})\n```\n\n\n---\n\n### Using Event Emitters\n\n```js\nvar events = require('events')\nvar emitter = new events.EventEmitter()\n\nemitter.on('knock', function() {\n  console.log('Who\\'s there?')\n})\n\nemitter.on('knock', function() {\n  console.log('Go away!')\n})\n\nemitter.emit('knock')\n```\n\n---\n\n### Inheriting from EventEmitter\n\n```js\n// job.js\nvar util = require('util')\nvar Job = function Job() {\n  // ...\n  this.process = function() {\n    // ...\n    job.emit('done', { completedOn: new Date() })\n  }\n}\n\nutil.inherits(Job, require('events').EventEmitter)\nmodule.exports = Job\n```\n\n---\n\n### Inheriting from EventEmitter\n\n```js\n// weekly.js\nvar Job = require('./job.js')\nvar job = new Job()\n\njob.on('done', function(details){\n  console.log('Job was completed at', details.completedOn)\n  job.removeAllListeners()\n})\n\njob.process()\n```\n\n---\n\n### Listeners\n\n```js\nemitter.listeners(eventName)\nemitter.on(eventName, listener)\nemitter.once(eventName, listener)\nemitter.removeListener(eventName, listener)\n```\n\n---\n\n# Other Node Patterns\n\nNode Patterns: From Callbacks to Observer: \u003chttp://webapplog.com/node-patterns-from-callbacks-to-observer/\u003e\n\nor\n\n\u003chttps://github.com/azat-co/node-patterns\u003e\n\n---\n\n# Problems with Large Data\n\n* Speed: Too slow because has to load all\n* Buffer limit: ~1Gb\n* Overhyped (JK)\n\n---\n\n# Streams\n\n## Abstractions for continuous chunking of data\n\n---\n\n# No need to wait for the entire resource to load\n\n---\n\n# Types of Streams\n\n* Readable\n* Writable\n* Duplex\n* Transform\n\n---\n\n## Streams Inherit from Event Emitter\n\n---\n\n# Streams are Everywhere!\n\n* HTTP requests and responses\n* Standard input/output (stdin\u0026stdout)\n* File reads and writes\n\n---\n\n# Readable Stream Example\n\n`process.stdin`\n\nStandard input streams contain data going into applications.\n\n---\n\n# This is achieved via a read operation.\n\n---\n\n# Input typically comes from the keyboard used to start the process.\n\n---\n\nTo listen in on data from stdin, use the `data` and `end` events:\n\n```js\n// stdin.js\nprocess.stdin.resume()\nprocess.stdin.setEncoding('utf8')\n\nprocess.stdin.on('data', function (chunk) {\n  console.log('chunk: ', chunk)\n})\n\nprocess.stdin.on('end', function () {\n  console.log('--- END ---')\n})\n```\n\n---\n\n# Demo\n\n`$ node stdin.js`\n\n---\n\n# New Interface `read()`\n\n```js\nvar readable = getReadableStreamSomehow()\nreadable.on('readable', () =\u003e {\n  var chunk\n  while (null !== (chunk = readable.read())) {\n    console.log('got %d bytes of data', chunk.length)\n  }\n})\n```\n\n^readable.read is sync but the chunks are small\n\n---\n\n# Writable Stream Example\n\n`process.stdout`\n\nStandard output streams contain data going out of the applications.\n\n---\n\n# This is done via a write operation.\n\n---\n\n# Data written to standard output is visible on the command line.\n\n---\n\n# Writable Stream\n\nTo write to `stdout`, use the `write` function:\n\n```js\nprocess.stdout.write('A simple message\\n')\n```\n\n---\n\n# What about HTTP?\n\n---\n\n```js\nconst http = require('http')\nvar server = http.createServer( (req, res) =\u003e {\n  req.setEncoding('utf8')\n  req.on('data', (chunk) =\u003e {\n    transform(chunk) // This functions is defined somewhere else\n  })\n  req.on('end', () =\u003e {  \n    var data = JSON.parse(body)\n    res.end()\n  })\n})\n\nserver.listen(1337)\n```\n\n---\n\n# Pipe\n\n\n```js\nvar r = fs.createReadStream('file.txt')\nvar z = zlib.createGzip()\nvar w = fs.createWriteStream('file.txt.gz')\nr.pipe(z).pipe(w)\n```\n\n^Readable.pipe takes writable and returns destination\n\n---\n\n## What data type to use for binary data?\n\n---\n\n### Buffers\n\nBinary data type, to create:\n\n* `Buffer.alloc(size)`\n* `Buffer.from(array)`\n* `Buffer.from(buffer)`\n* `Buffer.from(str[, encoding])`\n\nDocs: \u003chttp://bit.ly/1IeAcZ1\u003e\n\n---\n\n# Working with Buffer\n\n```js\n// buf.js\nvar buf = Buffer.alloc(26)\nfor (var i = 0 ; i \u003c 26 ; i++) {\n  buf[i] = i + 97 // 97 is ASCII a\n}\nconsole.log(buf) // \u003cBuffer 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a\u003e\nconsole.log(buf.toString('utf8')) // abcdefghijklmnopqrstuvwxyz\n```\n\n---\n\n# Buffer Convertion\n\n```js\nbuf.toString('ascii') // outputs: abcdefghijklmnopqrstuvwxyz\nbuf.toString('ascii', 0, 5) // outputs: abcde\nbuf.toString('utf8', 0, 5) // outputs: abcde\nbuf.toString(undefined, 0, 5) // encoding defaults to 'utf8', outputs abcde\n```\n\n---\n\n### Remember fs?\n\n```js\nfs.readFile('/etc/passwd', function (err, data) {\n  if (err) return console.error(err)\n  console.log(data)\n});\n```\n\n`data` is buffer!\n\n---\n\n# Demo\n\n```\n$ node server-stream\n```\n\n---\n\n# Streams and Buffer Demo\n\n```js\n// server-stream.js\napp.get('/stream', function(req, res) {\n  var stream = fs.createReadStream(largeImagePath)\n  stream.pipe(res)\n})\n```\n\n```\n$ node server-stream\n```\n\n\u003chttp://localhost:3000/stream\u003e\n\u003chttp://localhost:3000/non-stream\u003e\n\n---\n\n# Results in DevTools\n\n`/stream` responds faster!\n\n```\nX-Response-Time\n~300ms vs. 3-5s\n```\n\n---\n\n# Stream Resources\n\nStream automated workshop: \u003chttps://github.com/substack/stream-adventure\u003e\n\n```\n$ sudo npm install -g stream-adventure\n$ stream-adventure\n```\n\n\u003chttps://github.com/substack/stream-handbook\u003e\n\n\n---\n\n\n\n\n# How to scale a single threaded system?\n\n---\n\n# Cluster Usage\n\n* Master: starts workers\n* Worker: do the job, e.g., HTTP server\n\nNumber of processes = number of CPUs\n\n---\n\n# Clusters\n\n```js\nvar cluster = require('cluster')\nvar numCPUs = require('os').cpus().length\nif (cluster.isMaster) {\n  for (var i = 0; i \u003c numCPUs; i++) {\n    cluster.fork()\n  }\n} else if (cluster.isWorker) {\n  // your server code\n})\n```\n\n---\n\n# Cluster Demo\n\n1. Run `code/cluster.js` with node (`$ node cluster.js`).\n1. Install `loadtest` with npm: `$ npm install -g loadtest`\n1. Run load testing with: `$ loadtest  http://localhost:3000 -t 20 —c 10`\n\nPress control+c on the server terminal\n\n---\n\n# Cluster Libraries\n\n* Core cluster: lean and mean\n* strong-cluster-control (https://github.com/strongloop/strong-cluster-control), or `$ slc run`: good choice\n* pm2 (https://github.com/Unitech/pm2): good choice\n\n---\n\n### pm2\n\n\u003chttps://github.com/Unitech/pm2\u003e\n\n\u003chttp://pm2.keymetrics.io\u003e\n\nAdvantages:\n\n* Load-balancer and other features\n* 0s reload down-time, i.e., forever alive\n* Good test coverage\n\n---\n\n### pm2 Demo: Typical Express Server\n\n```js\nvar express = require('express')\nvar port = 3000\nglobal.stats = {}\nconsole.log('worker (%s) is now listening to http://localhost:%s',\n process.pid, port)\nvar app = express()\napp.get('*', function(req, res) {\n  if (!global.stats[process.pid]) global.stats[process.pid] = 1\n  else global.stats[process.pid] += 1;\n  var l ='cluser '\n    + process.pid\n    + ' responded \\n';\n  console.log(l, global.stats)\n  res.status(200).send(l)\n})\napp.listen(port)\n```\n\n---\n\n### pm2 Demo\n\nUsing `server.js`:\n\n```\n$ pm2 start server.js -i 0\n```\n\nIn a new window:\n\n```\n$ loadtest  http://localhost:3000 -t 20 -c 10\n$ pm2 list\n```\n\n---\n\n# Spawn vs Fork vs Exec\n\n* `require('child_process').spawn()` - large data, stream, no new V8 instance\n* `require('child_process').fork()` - new V8 instance, multiple workers\n* `require('child_process').exec()` - buffer, async, all the data at once\n\n---\n\n### Spawn Example\n\n```js\nfs = require('fs')\nprocess = require('child_process')\nvar p = process.spawn('node', 'program.js')\np.stdout.on('data', function(data)) {\n  console.log('stdout: ' + data)\n})\n```\n\n---\n\n### Fork Example\n\n```js\nfs = require('fs')\nprocess = require('child_process')\nvar p = process.fork('program.js')\np.stdout.on('data', function(data)) {\n  console.log('stdout: ' + data)\n})\n```\n\n---\n\n# Exec Example\n\n```js\nfs = require('fs')\nprocess = require('child_process')\nvar p = process.exec('node program.js', function (error, stdout, stderr) {\n  if (error) console.log(error.code)\n})\n```\n\n---\n\n# How to handle async errors?\n\n---\n\n\n# Handling Async Errors\n\nEvent Loop: Async errors are harder to handle/debug, because system loses context of the error. Then, application crashes.\n\nTry/catch is not good enough.\n\n---\n\n\n### Synchronous Error in Node\n\n```js\ntry {\n  throw new Error('Fail!')\n} catch (e) {\n  console.log('Custom Error: ' + e.message)\n}\n```\n\nFor sync errors try/catch works fine.\n\n---\n\n\n### Async Error Example\n\n```js\ntry {\n  setTimeout(function () {\n    throw new Error('Fail!')\n  }, Math.round(Math.random()*100))\n} catch (e) {\n  console.log('Custom Error: ' + e.message)\n}\n```\n\nThe app crashes!\n\n---\n\n# Me When Async Error's Thrown\n\n![inline](images/baby_elephant.gif)\n\n---\n\n### Async Errors\n\n How to deal with it?\n\n:sweat_smile:\n\n---\n\n## Best Practices for Async Errors?\n\n* Listen to all “on error” events\n* Listen to `uncaughtException`\n* Use `domain` (soft deprecated) or [AsyncWrap](http://blog.trevnorris.com/2015/02/asyncwrap-tutorial-introduction.html)\n* Log, log, log \u0026 Trace\n* Notify (optional)\n* Exit \u0026 Restart the process\n\n---\n\n### on('error')\n\nAnything that inherits from or creates an instance of the above: Express, LoopBack, Sails, Hapi, etc.\n\n```js\nserver.on('error', function (err) {\n  console.error(err)\n})\n```  \n\n---\n\n### on('error') Chained Method Example\n\n```js\nvar http = require(‘http’)\nvar server = http.createServer(app)\n  .on('error', function(e) {\n    console.log(‘Failed to create server’)\n    console.error(e)\n    process.exit(1)\n  })\n```\n\n---\n\n### on(‘error’) Named Variable Example\n\n```js\nvar req = http.request(options, function(res) {\n  // … processing the response\n})\n\nreq.on('error', function(e) {\n  console.log('problem with request: ' + e.message)\n})\n```\n\n---\n\n### uncaughtException\n\n`uncaughtException` is a very crude mechanism for exception handling. An unhandled exception means your application - and by extension Node.js itself - is in an undefined state. Blindly resuming means anything could happen.\n\n---\n\n### uncaughtException\n\nAlways listen to `uncaughtException`!\n\n```js\nprocess.on(‘uncaughtException’, handle)\n```\n\nor\n\n```js\nprocess.addListener('uncaughtException', handle)\n```\n\n---\n\n\n### uncaughtException Expanded Examples\n\n```js\nprocess.on('uncaughtException', function (err) {\n  console.error('uncaughtException: ', err.message)\n  console.error(err.stack)\n  process.exit(1)\n})\n```\n\nor\n\n```js\nprocess.addListener('uncaughtException', function (err) {\n  console.error('uncaughtException: ', err.message)\n  console.error(err.stack)\n  process.exit(1)\n```\n\n---\n\n### Domain\n\nThis module is softly deprecated in 4.0 (most likey will be separate from core module), but there's no alternatives in core as of now.\n\n---\n\n### Domain Example\n\n```js\nvar domain = require('domain').create()\ndomain.on('error', function(error){\n  console.log(error)\n})\ndomain.run(function(){\n  throw new Error('Failed!')\n})\n```\n\n---\n\n### Domain with Async Error Demo\n\ndomain-async.js:\n\n```js\nvar d = require('domain').create()\nd.on('error', function(e) {\n   console.log('Custom Error: ' + e)\n})\nd.run(function() {\n  setTimeout(function () {\n    throw new Error('Failed!')\n  }, Math.round(Math.random()*100))\n});\n```\n\n---\n\n# C++ Addons\n\n---\n\n## How to Write C/C++ binding for your IoT, hardware, drone, smartdevice, etc.?\n\n---\n\n### Node and C++\n\nCreate the `hello.cc` file:\n\n```c\n#include \u003cnode.h\u003e\n\nnamespace demo {\n\nusing v8::FunctionCallbackInfo;\nusing v8::HandleScope;\nusing v8::Isolate;\nusing v8::Local;\nusing v8::Object;\nusing v8::String;\nusing v8::Value;\n```\n\n---\n\n### Node and C++\n\nCreate the `hello.cc` file:\n\n```c\nvoid Method(const FunctionCallbackInfo\u003cValue\u003e\u0026 args) {\n  Isolate* isolate = args.GetIsolate();\n  args.GetReturnValue().Set(String::NewFromUtf8(isolate, \"capital one\"));\n}\n\nvoid init(Local\u003cObject\u003e exports) {\n  NODE_SET_METHOD(exports, \"hello\", Method);\n}\n\nNODE_MODULE(addon, init)\n\n}  // namespace demo\n```\n\n---\n\n### Creating `binding.gyp`\n\nCreate `binding.gyp`:\n\n```\n{\n  \"targets\": [\n    {\n      \"target_name\": \"addon\",\n      \"sources\": [ \"hello.cc\" ]\n    }\n  ]\n}\n```\n\n---\n\n### node-gyp\n\n```\n$ npm install -g node-gyp\n```\n\n\u003chttps://github.com/nodejs/node-gyp\u003e\n\n^Needs Python\n\n---\n\n### Configuring and Building\n\n```\n$ node-gyp configure\n$ node-gyp build\n```\n\nCheck for compiled `.node` files in build/Release/\n\n---\n\n### C++ Addons Examples\n\n\u003chttps://github.com/nodejs/node-addon-examples\u003e\n\n---\n\n### Including Addon\n\nCreate `hello.js` and include your C++ addon:\n\n```js\nvar addon = require('./build/Release/addon')\nconsole.log(addon.hello()) // 'capital one'\n```\n\nRun\n\n```\n$ node hello.js\n```\n\n---\n\n# Want to work with Node but your boss won't let you?\n\nCapital One is hiring ~2,000 more software engineers in UK, Canada and US.\n\n\u003chttps://jobs.capitalone.com\u003e\n\nWe use Node and other cutting-edge open source tech a lot! (React, Kotlin, Clojure, Angular 2, TypeScript, Go, etc.)\n\n---\n\n# Learn More\n\nNode at Capital One by Azat Mardan at Node Interactive 2015\n\n\u003chttps://www.youtube.com/watch?v=BJPeLJhv1Ic\u003e\n\n![inline](images/node-capital-one.png)\n\n\n---\n\n\n# 30-Second Summary\n\n1. Event Emitters\n1. Streams\n1. Buffers\n1. Clusters\n1. C++ Addons\n1. Domain\n\n---\n\n\n# Slides \u0026 Code :page_facing_up:\n\nEverything: \u003chttps://github.com/azat-co/you-dont-know-node\u003e\n\nor\n\njust PDF: \u003chttp://bit.ly/1VJWpQK\u003e\n\n\n---\n\n\n# My Contacts\n\nTwitter: @azat_co\nEmail: hi@azat.co\n\n---\n\n# Want to learn more about Node.js?\n\nCheck out [Node.University](http://node.university), [Webapplog.com](http://webapplog.com) and [NodeProgram.com](http://NodeProgram.com) for the best online and in-person education!\n\n\n---\n\n\n\n![inline](images/nu.png)\n\n\u003chttp://node.university\u003e\n\n---\n\n# One Last Thing 👉\n\n---\n\n# CodingHorror.com\n\n![inline](images/atwoods_law.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazat-co%2Fyou-dont-know-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazat-co%2Fyou-dont-know-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazat-co%2Fyou-dont-know-node/lists"}