Upload and review sensor readings to keep the crops happy and your farm productive.
The assignment was to create a fullstack application that would let users upload weather related data in CSV form for parsing and displaying. Emphasis was to be given to writing clean code and good instructions.
Kasvudata is many things: a NodeJS backend, that can parse the CSV files and store them in a MongoDB database, be it in the cloud, running locally or inside a Docker container. The backend is a REST API, documented with Swagger.
The frontend is a simple React client for displaying the 30 most recent entries of the sensor data.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Make sure you have a recent version of Node.js installed. To use the containers you will need to install Docker for your system.
Clone the repository.
git clone https://github.com/simosavonen/kasvudata.git
cd kasvudata
Rename the two .env.sample files as .env, located at the root of the project and in /server
directory.
Start two docker containers, one for the backend and one for MongoDB, by running the command:
docker-compose up
The command to shut down the docker containers: docker-compose down
The backend should now be running at http://localhost:6868/api
The Swagger generated API documentation is found at http://localhost:6868/api-docs
To upload CSV files, you can use the Swagger api-docs or open http://localhost:6868/api/files
Install Node.js modules and start the React client
cd client
npm install
npm start
The client will start at http://localhost:3000 and is configured to look for the backend at port 6868.
It is very limited in functionality. You should see a table of weather sensor data if you uploaded the CSV files. The client expands a row when clicked on, to reveal more data points.
It's also possible to run the command npm run build
and copy the contents of the /client/build
directory to /server/public
, the backend is configured to serve static files from that directory.
TODO: automate this.
To run the battery of tests for the backend, install Node.js modules on your local machine.
cd server
npm install
npm run test
The tests are found in directory /server/tests
and they use an in-memory version of MongoDB. This lets developers in a team run tests without interfering each other, compared to using a shared database.