Testing File Paths held in a Database with Node
If you have a database filled with file paths, you can use Node to verify that the files listed in the database exist on the server.
I will be using the Git bash shell in this article.
Open a Git bash shell and confirm that you have what you need to test the file system with Node.
$ git --version
git version 2.8.2.windows.1
$ node -v
$ npm -v
Now we can set up the project structure.
$ mkdir file-tests
$ cd file-tests
$ mkdir test
Using the Node Package Manager, we will create our package.json file to manage our dependencies.
$ npm init
You can complete the npm init questions as you see fit. Here is my initial package.json file.
Now we can bring in our dependencies.
$ npm install eslint --save-dev
$ npm install lodash mocha sequelize tedious --save
Here is my updated package.json file.
The first thing we added was eslint.
You can use eslint with its default settings or you can create a
Now that we have eslint, we can update the package.json file with a test to run it.
File Path Test
Now that the setup is complete, we can start writing tests.
Our tests rely on information that might change in the future. So we are going to create a config.js file.
Add a file to run the verification into the test folder.
Running the Test
We can update the package.json file with the script to run the tests.
I will bail out of testing if one content file fails. I set a 1 minute timeout for running the tests
and a 30 second slow warning in mocha. You can run the tests with "npm start".