This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const csvStringify = require("csv-stringify"); | |
const { Transform } = require('stream'); | |
const zlib = require("zlib"); | |
const { MongoClient } = require('mongodb'); | |
const url = 'mongodb://localhost:27017'; | |
const client = new MongoClient(url); | |
const dbName = 'myProject'; // your DB name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> | |
<head> | |
<title>Tasks' List</title> | |
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> | |
<meta content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport' /> | |
</head> | |
<body> | |
<!-- this data is just sample taken from datatables example --> | |
<table id="list" class="display" style="width:100%"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const router = express.Router(); | |
router.get('/pets/cats', (req, res) => { | |
res.send('10 cats'); | |
}); | |
router.get('/pets/dogs', (req, res) => { | |
res.send('5 dogs'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/44330807/713573 | |
(async () => { | |
// sync function | |
function syncFunc (opts) { | |
return 'done'; | |
} | |
const asyncSyncFunc = async (params) => { | |
return syncFunc(params); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source from 'parallel-transform' | |
var transform = require('parallel-transform'); | |
var stream = transform(5, {ordered: false}, function(data, callback) { // 10 is the parallism level | |
setTimeout(function() { | |
callback(null, data); | |
}, Math.random() * 1000); | |
}); | |
for (var i = 0; i < 20; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example from parallel-transform | |
var transform = require('parallel-transform'); | |
var stream = transform(5, function(data, callback) { // 5 is the parallism level | |
setTimeout(function() { | |
callback(null, data); | |
}, 1000); | |
}); | |
for (var i = 0; i < 20; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const {Transform} = require('stream'); | |
const split = require('split'); | |
const readStream = fs.createReadStream('./numbers'); | |
const writeStream = fs.createWriteStream('./evens'); | |
function test (chunk, cb) { | |
const val = parseInt(chunk.toString()); | |
if (val % 2 === 0) cb(null, val.toString() + '\n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source code from https://stackoverflow.com/a/19561718/713573 | |
const fs = require("fs"); | |
const {Transform} = require('stream'); | |
const split = require('split'); | |
const readStream = fs.createReadStream('./numbers'); | |
const evenWriteStream = fs.createWriteStream('./evens'); | |
const oddWriteStream = fs.createWriteStream('./odds'); | |
class Even extends Transform { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
marked --gfm README.md | sed 's/\.md">/.html">/g' > README.html | |
for i in `find ./docs/ -name '*md' ` | |
do | |
out=`echo $i |sed "s/\.md/.html"/g` | |
echo $i '->' $out | |
marked --gfm $i | sed 's/\.md">/.html">/g' > $out | |
done; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const {LoremIpsum} = require("lorem-ipsum"); | |
const lorem = new LoremIpsum(); | |
const ws = fs.createWriteStream('somefile.txt'); | |
// https://nodejs.org/api/stream.html#stream_event_drain | |
// Write the data to the supplied writable stream one million times. | |
// Be attentive to back-pressure. | |
function writeOneMillionTimes(writer, data, encoding, callback) { | |
let i = 1000000; | |
write(); |