Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 141 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,147 @@
FROM node:13-alpine
<div id="top"></div>

WORKDIR /app
<br />
<div align="center">
<a href="https://github.com/codebymini/healthnode">
<img src="images/logo.png" alt="Logo" width="80" height="80">
</a>

COPY package.json package-lock.json ./
<h3 align="center">HealthNode</h3>

RUN npm install --production
<p align="center">
Living with diabetes type 1 is a great hazzle trying to find balance between carbs and
insulin. Since there are multiple factors besides the two mentioned above, this project
aims at visualising the correlation between physical activity and glucose levels in the blood.
<br />
<br />
<a href="https://github.com/codebymini/healthnode/issues">Report Bug</a>
·
<a href="https://github.com/codebymini/healthnode/issues">Request Feature</a>
</p>
</div>

COPY . .

EXPOSE 3000

CMD node index.js
<details>
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#about-the-project">About The Project</a>
<ul>
<li><a href="#built-with">Built With</a></li>
</ul>
</li>
<li>
<a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li><a href="#usage">Usage</a></li>
<li><a href="#roadmap">Roadmap</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#license">License</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
</ol>
</details>
<br />


## About The Project

This is a multipart project containing an iPhone app, Back- and Front-end in Node.js and Kubernetes deployment definitions. It also utilize a Atlas MongoDB.

The repositories used in this project:
* <a href="https://github.com/CodeByMini/HealthNode">HealthNode</a>
* <a href="https://github.com/CodeByMini/HealthNodeApp">HealthNodeApp</a>
* <a href="https://github.com/CodeByMini/HealthNodeApi">HealthNodeApi</a>
* <a href="https://github.com/CodeByMini/HealthNodeWeb">HealthNodeWeb</a>



<p align="right">(<a href="#top">back to top</a>)</p>

## System Overview
<img src="images/api-routes.png">

<p align="right">(<a href="#top">back to top</a>)</p>

### Built With
* [Node.js](https://nodejs.dev/)

<p align="right">(<a href="#top">back to top</a>)</p>


## Getting Started
Install Node.js from https://nodejs.dev/

### Prerequisites
Create .env file and populate the following variables:
>PORT=
>
>MONGODB=
>
>APIKEY=


### Installation
Install the packages:

```npm i express```

```npm i mongoose```

<p align="right">(<a href="#top">back to top</a>)</p>


## Usage
Run app with:

```node app.js```

<p align="right">(<a href="#top">back to top</a>)</p>



## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

<p align="right">(<a href="#top">back to top</a>)</p>


## License

Distributed under the MIT License. See `LICENSE.txt` for more information.

<p align="right">(<a href="#top">back to top</a>)</p>



## Contact

Daniel Mini Johansson - daniel@codebymini.se

[![LinkedIn][linkedin-shield]][linkedin-url]

Project Link: [https://github.com/codebymini/healthnode](https://github.com/codebymini/healthnode)


<p align="right">(<a href="#top">back to top</a>)</p>


[license-shield]: https://img.shields.io/github/license/codebymini/healthnode.svg?style=for-the-badge
[license-url]: https://github.com/codebymini/healthnode/blob/master/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/https://www.linkedin.com/in/daniel-johansson-4b099219a/
95 changes: 31 additions & 64 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,75 +36,42 @@ const health = new mongoose.Schema({

const Health = mongoose.model('health', health);

app.get('/getrecords', function(req, res) {
Health.find({}).sort([['date']]).exec(function(err, health){
console.log("data sent")
res.send(health);
});
});

app.get('/getrecords/:device', function(req, res) {
console.log(req.params.device)
Health.find({device: req.params.device}).sort([['date']]).exec(function(err, health){
console.log("data sent")
res.send(health);
});
});

app.get('/delete/:device', function(req, res){
if(req.query.apikey==APIKEY){
Health.deleteMany({device:req.params.device}).exec(function(err, res) {});
res.send("All records deleted")
}
})

app.get('/delete', function(req, res){
if(req.query.apikey==APIKEY){
Health.deleteMany({}).exec(function(err, res) {});
res.send("All records deleted")
}
})

app.get('/senddata', function(req, res) {
console.log()
if(req.query.apikey==APIKEY){
const health = new Health({
date: req.query.date,
value: req.query.value,
})
console.log(health.date)
console.log(health.value)
health.save(function(err){
if(!err){
res.send("Records recorded. must been a record!");
}else{
console.log(err)
}
})
}
else{
res.send("<center><iframe width='560' height='315' src='https://www.youtube.com/embed/K3PrSj9XEu4' title='YouTube video player' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe></center>");
}
});

app.post('/postdata', function(req, res){
if(req.get("apikey")==APIKEY){
let data = req.body;
Health.insertMany(data).then(function(){
console.log("Data inserted") // Success
res.send({
'status': 'success'
});
}).catch(function(error){
app.route('/api/:device')
.get(function(req, res) {
console.log(req.params.device)
console.log("got data from: " + req.params.device)
Health.find({device: req.params.device}).sort([['date']]).exec(function(err, health){
console.log("data sent")
res.send(health);
});
})

.delete(function(req, res){
console.log("data deleted for: " + req.params.device)
if(req.query.apikey==APIKEY){
Health.deleteMany({device:req.params.device}).exec(function(err, res) {});
res.send("All records deleted")
}
})

.post(function(req, res){
if(req.get("apikey")==APIKEY){
let data = req.body;
Health.insertMany(data).then(function(){
console.log("Data inserted for: "+ req.params.device) // Success
res.send({
'status': 'success'
});
}).catch(function(error){
console.log(error) // Failure
res.send({
'status': 'failed'
});
});
}
else{
res.send("Wrong APIKEY")
}});
}
else{
res.send("Wrong APIKEY")
}});

app.listen(PORT, function() {
console.log("listening on port " + PORT);
Expand Down
Binary file added images/.DS_Store
Binary file not shown.
Binary file added images/api-routes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/app.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/connect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/editenv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/mongodb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/system-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.