Browse By – Make it modular

Recently I was playing with the exercises from the fantastic Below is my solution to “Make it modular” exercise. Of course you can improve it eg. with the use of Regex but I just wanted to keep it simple for the start. 

So the first file with the name myprogram.js:

var module = require("./module.js");
module(process.argv[2],process.argv[3], function(err , list){
	if(err) return console.log("Error:", err)

	for(var s =0; s<list.length; s++){="" console.log(list[s])="" }="" });<="" pre="">

and the second module.js:

module.exports = function(path, extension, callback){
	var fs = require('fs');
	var flist = [];
	fs.readdir(path, function(err, list){		
			return callback(err);

		for (var i =0; i< list.length; i++){
			  if(list[i].indexOf("." + extension) >-1){
		return	callback(null,flist)

Leave a Reply

Your email address will not be published. Required fields are marked *