#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
require('./bar') // this will load file ./bar.js
require('bar')
// this is looking module in node_modules
// first ./node_modules/bar
// then ../node_modules/bar
// then ../../node_modules/bar
// until /node_modules/bar
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
simple version
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
const http = require('http') // buildin module
const lib = require('./lib') // local module
const toto = require('./toto.json') // json file
#ege-academy-nodejs @rbung @yagong
module.exports = function() { // export a default function
// lib logic
}
module.exports = { // export several functions
foo: function() {},
bar: function() {},
}
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
const fs = require('fs')
const readFile = require('util').promisify(fs.readFile)
readFile(`${__dirname}/module-usage/toto.json`, 'utf-8')
.then(data => console.log(data))
.catch(err => console.error(err))
#ege-academy-nodejs @rbung @yagong
npx vtop
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
🚀 Handle large amounts data in a very efficient way 😎
Â
#ege-academy-nodejs @rbung @yagong
#ege-academy-nodejs @rbung @yagong
// Read a big file and write the content into the http response
const fs = require('fs');
const server = require('http').createServer();
server.on('request', (req, res) => {
const src = fs.createReadStream('./big.file');
src.pipe(res);
});
server.listen(8000);
// Compress a big file
const gzip = require('zlib').createGzip();
const fs = require('fs');
const inp = fs.createReadStream('The.Matrix.1080p.mkv');
const out = fs.createWriteStream('The.Matrix.1080p.mkv.gz');
inp.pipe(gzip).pipe(out);
#ege-academy-nodejs @rbung @yagong
readableSrc
.pipe(transformStream1)
.pipe(transformStream2)
.pipe(finalWrtitableDest)
readable.on('data', (chunk) => {
writable.write(chunk);
});
#ege-academy-nodejs @rbung @yagong
https://github.com/rbung/ExerciceTransactionAnalyser
#ege-academy-nodejs @rbung @yagong