Skip to content

Instantly share code, notes, and snippets.

@leommoore
Last active October 8, 2015 13:17
Show Gist options
  • Select an option

  • Save leommoore/3337411 to your computer and use it in GitHub Desktop.

Select an option

Save leommoore/3337411 to your computer and use it in GitHub Desktop.
Node - Using Command Line Parameters

#Node - Using Command Line Parameters

//run from shell - node ls.js .
console.log('Param1: ' + process.argv[0]); // Node
console.log('Param2: ' + process.argv[1]); // ls.js
console.log('Param3: ' + process.argv[2]); // .        - current directory
console.log('---------------------------------------------------'); 
var fs = require('fs');
var dir = '.';

if (process.argv[2]) {
	dir = process.argv[2];
}

var files = fs.readdirSync(dir);
for (fn in files) {
	console.log(files[fn]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment