This project provides a tool and a REST api allowing to do the following :
- Get the 200 last posts of the VDM website (http://www.viedemerde.fr/) and store them to a Mongo database.
- Manipulate the posts through a REST api.
- Nodejs
- Local mongodb running
$ npm install grunt-cli -g$ npm install mocha -gGo to the root of the project and use the following command line :
$ npm installDatabase settings are available in /config/config.js
$ grunt serveThis will run the REST api.
/!\ The REST api must be running to use this command. /!\
$ grunt get-postsThis will retrieve the 200 last posts from http://www.viedemerde.fr/ and store them to the database.
/!\ The REST api must be running to use this command. /!\
$ grunt delete-postsThis will delete all the posts.
The posts can be access on localhost with the default port 3000. You can modify the port by modifying the environment variable 'PORT'.
The route to get posts is the following :
/api/posts
Output :
{
"posts":[
{
"_id":1,
"content":"This is the content.",
"date":"2014-01-0100:00:00",
"author":"Genius"
}
],
"count":1
}
Several parameters are available :
from=YYYY-MM-DDallow to get posts from this dateto=YYYY-MM-DDallow to get posts until this dateauthor=XXXXXallow to get posts from this author
You can access one post with the following route :
/api/posts/<id>
Output :
{
"post": {
"id":1,
"content":"This is the content.",
"date":"2014-01-0100:00:00",
"author":"Genius"
}
}
/!\ The REST api must be running to launch unit tests /!\
Unit tests can be run with the following command :
$ grunt test/!\ Running 'grunt test' will clear the database BEFORE and AFTER the tests /!\
If you want to run a test one at a time, you can use the following command :
$ mocha <name-of-the-test-file>The application is divided in 5 parts :
-
[api]
- The controllers folder contains js files that will build the CRUD requests.
- The models folder contains js files that will define a mongodb document structure.
- The routes folder contains js files that will defines the routes of the REST api.
-
[tests]
This folder contains js files needed to run unit tests.
-
[vdm-data]
This folder contains js files needed to extract and parse the data from the VDM website.
-
[scripts]
This folder contains scripts that allows to delete all posts from the database and launch the data transfer between VDM website and the database.
-
[config]
This folder contains all configurations like the database uri, express settings ...