This file contains hidden or 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
var stream = require('readable-stream'); | |
var mmm = require('mmmagic'); | |
var mimeChecker = new stream.Transform(); | |
mimeChecker.data = []; | |
mimeChecker.mimeFound = false; | |
mimeChecker._transform = function (chunk, encoding, done) { | |
var self = this; | |
if (self.mimeFound) { | |
self.push(chunk); |
This file contains hidden or 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
var stream = require('stream'); | |
var JSONStream = require('JSONStream'); | |
var inputStream = new stream.PassThrough(); | |
var jsonStream = JSONStream.parse('*'); | |
var finalStream = new stream.Writable({ objectMode: true }); | |
finalStream._write = function (doc, encoding, done) { | |
console.log(doc); | |
done(); | |
}; |
This file contains hidden or 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
// node: v0.10.21 | |
// request: 2.27.0 | |
var request = require('request'); | |
var fs = require('fs'); | |
var r = request.post("http://server.com:3000/"); | |
// See http://nodejs.org/api/stream.html#stream_new_stream_readable_options | |
// for more information about the highWaterMark | |
// Basically, this will make the stream emit smaller chunks of data (ie. more precise upload state) | |
var upload = fs.createReadStream('f.jpg', { highWaterMark: 500 }); |
This file contains hidden or 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
process.on('message', function(m) { | |
console.log('Just received a message from parent: ' + JSON.stringify(m)); | |
if (m.exit === "true") process.exit(); | |
}); |
This file contains hidden or 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
$ node -v | |
v0.10.16 | |
$ node index.js | |
/root/tmp/node_modules/async/lib/async.js:710 | |
process: function () { | |
^ | |
RangeError: Maximum call stack size exceeded |
This file contains hidden or 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
#!/usr/bin/nodejs | |
var levelup = require('levelup'); | |
var http = require('http'); | |
var util = require('util'); | |
var Transform = require('stream').Transform || require('readable-stream').Transform; | |
var server = http.createServer(onRequest); | |
// Save something in db |
This file contains hidden or 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
dd if=/dev/zero of=input.txt bs=512k count=50 |
This file contains hidden or 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
~/tmp ❯❯❯ node index.js | |
null | |
[ {}, {}, {} ] |
This file contains hidden or 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
var csv = require('csv'); | |
var async = require('async'); | |
var fs = require('fs'); | |
var MongoClient = require('mongodb').MongoClient; | |
MongoClient.connect('mongodb://localhost:27017/csvdb', function(err, db) { | |
if (err) throw err; | |
var collection = db.collection('myCSVs'); | |
var queue = async.queue(collection.insert.bind(collection), 5); |
This file contains hidden or 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
var fs = require('fs'); | |
var express = require('express'); | |
var app = express(); | |
app.get('/', function (req, res) { | |
res.attachment(); | |
fs.createReadStream('test.pdf').pipe(res); | |
}); | |
app.listen(8080); |
OlderNewer