Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| 56-tools:node [2016/12/21 01:55] – [async & co] Roge | 56-tools:node [2017/11/26 18:02] (Version actuelle) – [Child Process] Roge | ||
|---|---|---|---|
| Ligne 28: | Ligne 28: | ||
| + | ===== install nodejs ===== | ||
| + | |||
| + | https:// | ||
| ===== express ===== | ===== express ===== | ||
| Ligne 86: | Ligne 89: | ||
| - | ===== pug (jade) ===== | + | ===== pug (former |
| Ligne 230: | Ligne 233: | ||
| [[http:// | [[http:// | ||
| + | |||
| + | < | ||
| + | 'use strict'; | ||
| + | var async = require(" | ||
| + | |||
| + | function makeLoopFunction(label, | ||
| + | return function(callback) { | ||
| + | // console.log(label+val); | ||
| + | return callback(null, | ||
| + | }; | ||
| + | } | ||
| + | |||
| + | function done (err, result) { | ||
| + | console.log(' | ||
| + | console.log(result); | ||
| + | } | ||
| + | |||
| + | var funcs = []; | ||
| + | for(var i = 0; i < 3; i++) { | ||
| + | funcs.push(makeLoopFunction(' | ||
| + | } | ||
| + | async.parallel(funcs, | ||
| + | // cbk done: 3 | ||
| + | // [ { val: 0, label: 'test 5: ' }, | ||
| + | // { val: 1, label: 'test 5: ' }, | ||
| + | // { val: 2, label: 'test 5: ' } ] | ||
| + | </ | ||
| Ligne 239: | Ligne 269: | ||
| < | < | ||
| 'use strict'; | 'use strict'; | ||
| - | var Promise = require("bluebird"); | + | var Promise = require('bluebird'); |
| - | function | + | function |
| - | //console.log(label+i); | + | var start = new Date().getTime(); |
| - | return | + | for (var i = 0; i < 1e7; i++) { |
| + | if ((new Date().getTime() - start) > milliseconds){ | ||
| + | console.log('sleep: '+milliseconds); | ||
| + | return milliseconds; | ||
| + | } | ||
| + | } | ||
| } | } | ||
| - | var testFuncs = []; | + | Promise.all([sleep(30), sleep(60)]) |
| - | for(var i = 0; i < 3; i++) { | + | .then(function(res){ |
| - | testFuncs.push(testFunction(' | + | console.log(res); |
| - | } | + | }); |
| + | // sleep: 30 | ||
| + | // sleep: 60 | ||
| + | // [ 30, 60 ] | ||
| + | </ | ||
| - | console.log(testFuncs[1]); | + | ===== Desktop app ===== |
| - | Promise.all(testFuncs) | ||
| - | .then(function(values) { | ||
| - | | ||
| - | | ||
| - | }); | ||
| - | // all the function were done | + | * Electron (ex Atom shell): http://github.com/electron/electron ou http:// |
| - | // [ { i: 0, test: 'test: ' }, | + | * Exemples: https://github.com/ |
| - | // { i: 1, test: 'test: ' | + | |
| - | // { i: 2, test: 'test: ' } ] | + | * NW.js (ex Node webkit): http://nwjs.io/ |
| - | </code> | + | |
| + | [[https:// | ||
| + | |||
| + | ===== Child Process ===== | ||
| + | Permet d'exécuter des commandes systèmes. | ||
| + | |||
| + | |||
| + | https://medium.freecodecamp.org/ | ||
| + | |||
| + | |||
| + | ===== PM2: production process manager for Node.js ===== | ||
| + | |||
| + | |||
| + | http:// | ||