Skip to content

Instantly share code, notes, and snippets.

@kopasetik
Last active August 29, 2015 14:01
Show Gist options
  • Save kopasetik/16458b7f3720bf203079 to your computer and use it in GitHub Desktop.
Save kopasetik/16458b7f3720bf203079 to your computer and use it in GitHub Desktop.
Learnyounode
(function(){
args = process.argv;
args.shift();
args.shift();
var total = args.reduce(function(a,b){
return parseInt(a,10) + parseInt(b,10);
});
console.log(total);
})()
var fs = require('fs');
var directory = process.argv[2],
extension = process.argv[3];
//console.error(process.argv);
fs.readdir(directory, function(err, list) {
if (err) {
console.error(err);
return;
}
list.filter(function(input){
var reggie = new RegExp( ".*\\." + extension + "$", "g");
return reggie.test(input);
}).
forEach(function(x){
console.log(x)
});
});
var fs = require('fs');
var path = require('path');
module.exports = function (dir, ext, charlie){
fs.readdir(dir, function(err, list) {
if (err) {
charlie(err, null);
return;
}
var lisa = list.filter(function(input){
var paddy = path.extname(input);
return paddy == ("." + ext);
});
charlie(null, lisa);
});
};
var fs = require('fs')
var path = require('path')
fs.readdir(process.argv[2], function (err, list) {
list.forEach(function (file) {
if (path.extname(file) === '.' + process.argv[3])
console.log(file)
})
})
var file = process.argv[2];
var fs = require('fs');
fs.readFile(file, function(err, data){
if (err) throw err;
console.log(data.toString().match(/\n/g).length);
});
var file = process.argv[2];
var fs = require('fs');
var doc = fs.readFileSync(file);
var x = doc.toString().match(/\n/g).length;
console.log(x);
var filterFcn = require('./filteredLsModule');
filterFcn(process.argv[2], process.argv[3], function(err, list) {
if (err) {
console.error("This is the error: " + err);
}
list.forEach(function(argument) {
console.log(argument);
});
});
var myTest = require('./moduleTest2');
myTest();
module.exports = function(){
console.log("Hello");
};
console.log("HELLO WORLD")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment