ra100 / express-js-test-app

Test app to process web request and write to database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node.js tracker

This is test app that processes web request and writes data to database and json file.

Assignment

Create a Node.js application that

  • Responds only on a HTTP route /track.

  • Reads the data from request. (There are multiple options: pick the one you seem fit.)

  • Appends the data to a JSON file

  • If there is a count parameter in the data, the application increments the count value in a database by the value of given count parameter. (The database can be redis, mongodb, mysql, ... pick yourself).

  • Has one or more unit test

Installation and running

You will need nodejs and mongodb server.

Clone the repository, open folder and install modules:

git clone git@github.com:ra100/express-js-test-app.git
cd express-js-test-app
npm install

Run tests:

npm run test

If everything is fine, run the app:

npm run app

Usage

Configuration is in app/config.js, you can change default port (1337), database connection uri, table name and path to json file.

By default app runs on port 1337, open browser http://127.0.0.1:1337/track, every other path will return Not Found status 404.

You can use GET or POST request to send data to /track.

GET /track

You can pass parameters to this request, e.g. /track?log=caladan&count=1&data=atreides. This will be appended t oarray in json file and will increase count value in database by values passed in parameter.

POST /track

You can pass data to this request, e.g.:

{
    "log": "Caladan",
    "count": 1,
    "house": "Atreides"
}

This will be appended to array in json file and will increase count value in database by values passed in parameter.

About

Test app to process web request and write to database

License:GNU General Public License v3.0


Languages

Language:JavaScript 80.2%Language:CoffeeScript 19.8%