For a mean.js project I am working on, I have a csv file of data that I need to check against in one of my server controllers. Instead of opening the csv file in the controller every time I do this check I want to move all of the data to my Mongo Database and just do a quick query for the check. Normally, I would do this database manipulation with a simple python script, however for this project I am working on a Mean stack supplied by Mean.js, with a team of a few engineers, on several different environments.
So, what I want to do is figure out a way to automatically create and populate this database within my mean.js app so:
I am using grunt as an application-wide task manager, but it runs each task every time the application is built which means it would do this repetitively.
Does anyone have any better suggestions on how to do this?
Two suggestions:
First, you could use npm scripts: https://docs.npmjs.com/misc/scripts
So, for instance if your "create database" script is a python file you would add this to your package.json
:
{
...
"scripts": {
"createdb": "python create_database.py"
}
...
}
And now you can run it when you need it like this:
npm run-script createdb
Still, this is very manual. Which leads us to my second suggestion:
You can create a grunt task that populates your database, and after running creates a hidden file indicating that it has been run. Just before running you check if the file is present, if so, you skip the task.
Add the hidden file to your .gitignore
and every time your project is cloned and grunt is fired up, your database will be populated just once.