Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| pub:node.js [2014/06/25 07:54] – Marco Krage | pub:node.js [2017/09/27 13:26] (aktuell) – Marco Krage | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| ====== Node.js ====== | ====== Node.js ====== | ||
| - | ===== yargs (Arguments) ===== | + | |
| - | Commandline Parameter | + | ===== dirty ===== |
| - | https://github.com/chevex/yargs | + | Key Value Database |
| + | <code javascript> | ||
| + | var dirty = require(' | ||
| + | var db = dirty('/ | ||
| + | var data = db.get(' | ||
| + | db.set(' | ||
| + | </ | ||
| + | |||
| + | ===== request ===== | ||
| + | HTTP Requests ([[https:// | ||
| + | <code javascript> | ||
| + | var request = require(' | ||
| + | request(url, | ||
| + | if (error || response.statusCode != 200) { console.error(error, | ||
| + | console.log(html); | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | ===== cheerio ===== | ||
| + | jQuery like DOM Parser ([[https:// | ||
| + | <code javascript> | ||
| + | var cheerio = require(' | ||
| + | var $ = cheerio.load(body); | ||
| + | </ | ||
| + | |||
| + | ===== underscore ===== | ||
| + | Utiliys ([[https:// | ||
| + | <code javascript> | ||
| + | var _ = require(' | ||
| + | </ | ||
| + | |||
| + | ===== dialog ===== | ||
| + | Window Prompts ([[https:// | ||
| + | <code javascript> | ||
| + | var dialog = require(' | ||
| + | dialog.info(" | ||
| + | |||
| + | |||
| + | |||
| + | ===== commander | ||
| + | Commandline Parameter | ||
| <code javascript> | <code javascript> | ||
| - | $ /xup.js --r=55 -s foo -b -c | + | var argv = require(' |
| - | var argv = require('yargs') | + | argv |
| - | .default('rif', | + | .version('0.0.1') |
| - | .demand(['s',' | + | .option('-p, --peppers', |
| - | .argv; | + | .option('-c, --cheese |
| + | | ||
| - | argv.r => 55 | + | console.log(' |
| - | argv.s => foo | + | if (argv .peppers) console.log(' |
| - | argv.b => true | + | console.log(' |
| - | argv.c => true | + | |
| </ | </ | ||
| ===== prompt ===== | ===== prompt ===== | ||
| - | Userinput Abfrage | + | Userinput Abfrage |
| - | https:// | + | |
| <code javascript> | <code javascript> | ||
| Zeile 32: | Zeile 71: | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ===== fs-extra ===== | ||
| + | Extra FileSystem tools ([[https:// | ||
| + | |||
| + | <code javascript> | ||
| + | var fs = require(' | ||
| + | |||
| + | // Async with promises: | ||
| + | fs.copy('/ | ||
| + | .then(() => console.log(' | ||
| + | .catch(err => console.error(err)) | ||
| + | |||
| + | // Async with callbacks: | ||
| + | fs.copy('/ | ||
| + | if (err) return console.error(err) | ||
| + | console.log(' | ||
| + | }) | ||
| + | |||
| + | // Sync: | ||
| + | try { | ||
| + | fs.copySync('/ | ||
| + | console.log(' | ||
| + | } catch (err) { | ||
| + | console.error(err) | ||
| + | } | ||
| + | </ | ||
| ===== mime ===== | ===== mime ===== | ||
| - | MIME-Type | + | MIME-Type |
| https:// | https:// | ||
| Zeile 48: | Zeile 114: | ||
| ===== async ===== | ===== async ===== | ||
| - | Queue, Warteschlange | + | Queue, Warteschlange |
| - | https:// | + | |
| <code javascript> | <code javascript> | ||
| Zeile 71: | Zeile 136: | ||
| ===== socket.io ===== | ===== socket.io ===== | ||
| - | Realtime Web Communication | + | Realtime Web Communication |
| - | https:// | + | |
| <code javascript server.js> | <code javascript server.js> | ||
| Zeile 89: | Zeile 153: | ||
| io.on(' | io.on(' | ||
| socket.on(' | socket.on(' | ||
| - | // | + | // send to current request socket client |
| - | socket.broadcast.emit(' | + | |
| + | |||
| + | | ||
| + | io.sockets.emit(' | ||
| + | |||
| + | // sending to all clients except sender | ||
| + | socket.broadcast.emit(' | ||
| + | |||
| + | | ||
| + | socket.broadcast.to(' | ||
| + | |||
| + | // sending to all clients in ' | ||
| + | io.sockets.in(' | ||
| + | |||
| + | // sending to individual socketid | ||
| + | io.sockets.socket(socketid).emit(' | ||
| }); | }); | ||
| }); | }); | ||
| Zeile 113: | Zeile 192: | ||
| ===== mkdirp===== | ===== mkdirp===== | ||
| - | https:// | + | ([[https:// |
| <code javascript> | <code javascript> | ||
| Zeile 125: | Zeile 204: | ||
| ===== validator ===== | ===== validator ===== | ||
| - | Eingabe Überprüfung | + | Eingabe Überprüfung |
| - | https:// | + | |
| <code javascript> | <code javascript> | ||
| Zeile 133: | Zeile 211: | ||
| </ | </ | ||
| - | ===== colors | + | ===== chalk ===== |
| - | Farben in der Console | + | Farben/ |
| - | https:// | + | |
| <code javascript> | <code javascript> | ||
| - | var colors | + | var chalk = require(' |
| + | |||
| + | // Combine styled and normal strings | ||
| + | log(chalk.blue(' | ||
| + | |||
| + | // Compose multiple styles using the chainable API | ||
| + | log(chalk.blue.bgRed.bold(' | ||
| + | |||
| + | // Pass in multiple arguments | ||
| + | log(chalk.blue(' | ||
| - | console.log(' | + | var error = chalk.bold.red; |
| - | console.log('i like cake and pies'.underline.red) // outputs red underlined text | + | var warning = chalk.keyword('orange'); |
| - | console.log(' | + | console.log(error('Error!')); |
| - | console.log(' | + | console.log(warning('Warning!')); |
| </ | </ | ||