A small-ish Node JS API allowing to receive data from an Iskra JS (in Russian) based meteo-station and write it to Mongo DB. API includes all the usual method goodness: GET
, POST
, PUT
и DELETE
. It also uses Basic
auth via HTTP
.
💫 Chasing a dream.
Before starting the development set up MongoDB on your server.
Clone repo to the server:
git clone https://github.com/boboshko/zarya-api.git
Go to cloned repo directory:
cd zarya-api
Install all the necessary packages:
npm install
Add values to the environment keys. For example:
export zaryaUrlMongo="mongodb://localhost:27017/"
export zaryaDbName="dbName"
export zaryaCollectionName="collectionName"
export zaryaPort=3012
You can use the same set of values in the app/config/config.js
file instead:
module.exports = {
zaryaUrlMongo: process.env.zaryaUrlMongo || 'mongodb://localhost:27017/',
zaryaDbName: process.env.zaryaDbName || 'dbName',
zaryaCollectionName: process.env.zaryaCollectionName || 'collectionName',
zaryaPort: process.env.zaryaPort || 3012,
};
This API uses Basic
auth via HTTP
. Login and password are stored in the zaryaUsers
variable in app/data/auth.js
.
You can choose more complex login/password pair, for sure:
const zaryaUsers = { 'sdoJfde342': 'dskSlK4iu3' };
Created primarily for Iskra JS, this API can work with other shields, too.
Validation scheme is stored in app/data/model.js
and by default looks like this:
{
"station_id": Number,
"created_at": Number,
"date_count": Number,
"temperature": Number,
"pressure": Number
}
This scheme can also be changed.
Starting up:
npm run start
For API requests use:
<YOUR_SERVER_IP>:3012/zarya