If you have been using computers as long as I have you might have by now come across the use of glob patterns as a way to use a * wildcard to represent any string of characters. I am pretty comfortable with this method of selecting files that fit a certain pattern, and the npm package glob is a great solution for selecting files in a node.js environment.
This is a post on the npm package known as glob that allows for matching files that fit a given glob pattern. Out of the box it is not a complete file system walker, but it is a great tool for making such a project with glob pattern support. For more information on file system walkers you might want to check out my post on them to know about some options that are all ready out there before making your own solution. In this post I am also using version 7.1.3 of glob.
It is a way of making use of a wildcard character * to represent zero or more characters so that:
Will match any file with a .txt extension which will match helloworld.txt, and readme.txt, but not index.js in a given directory. This is something that I have been using for years when it comes to filtering files in file system managers, command line interface terminals an so forth. Globs might be less powerful then regEx patterns, but for most use case seniors simplified glob patterns are still good enough to get the job done.
The name of the package is just simply glob, as such I can add it to a node.js project link this
In a test project folder I made a simple basic.js file that looks like this:
The ** wildcard can be used to search for what is in the current working directory, and any additional subdirectories so that:
will search for and compile a list a file names for each mark down file found in the current working path and any additional path in the current working folder.
If three arguments are passed to to glob the second can be an options object, and one of the many options that can be changed is the current working directory which by default is what is returned by process.cwd() in node.js.
I looks like glob is just for matching files, but when it comes to actually reading the contents of the files and additional solution will need to be used in conjunction with glob. So out of the box it is not really a complete file system walker, but it is a valuable tool to create a walker from the ground up that will have support for glob patterns.
This is a great node.js solution to get working with glob patterns quickly. I might expand more on this with respect to the many diffrent options that can be given, but for now there is the readme of the project. ON MY GLOB!