├── README.md
├── assets
├── body.png
└── header.png
├── docker-compose.yml
├── express
├── Dockerfile.template
├── package.json
├── public
│ ├── header.png
│ ├── index.html
│ ├── main.js
│ └── styles.css
├── server.js
└── views
│ └── index.ejs
└── sensor
├── Dockerfile.template
├── src
└── main.py
└── start.sh
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # Express and MongoDB example project
4 |
5 | To demonstrate the use of a 64-bit container, we’ve developed a sample multi-container project that uses a few different technologies. The main idea is to plot a live chart containing the temperature and humidity of any city in the world.
6 |
7 | ### What you will need:
8 | - A download of the project from [GitHub](https://github.com/balena-io-playground/express-mongo-sample)
9 | - Software to flash an SD card ([balenaEtcher](https://balena.io/etcher))
10 | - A free [balenaCloud](https://balena.io/cloud) account to setup and manage the Pi Download and install the [balena CLI tools](https://github.com/balena-io/balena-cli/blob/master/INSTALL.md) - to be installed on your computer, allowing you to install the project code on the Raspberry Pi 4.
11 |
12 | You will also need to [set up environment variables](https://www.balena.io/docs/learn/manage/serv-vars/#environment-and-service-variables) from the balena dashboard:
13 |
14 | | Name | Value
15 | | -----------------|------------------------------------
16 | | CITY_LATLNG | The code corresponding to the latitude and longitude of the desired city comma separated. Ex: `38.722252,-9.139337`.
17 | | API_KEY | [api key](https://darksky.net/dev) retrieved after signing up at `https://darksky.net`|
18 | | FREQ | Frequency(in minutes) with which to retrieve weather data. |
19 |
20 |
21 | > To get the Lat & Long for your city, you can use [latlong.net](https://www.latlong.net/) and type the name of the desired city, such as Lisbon or London. On the `environment variable`, just combine both information comma separated such as `38.722252,-9.139337`.
22 |
23 | ### About the project:
24 |
25 | The project is divided into three containers:
26 | * A mongoDB database instance with persistent storage, in which we will store all data.
27 | * A Python 3 application that fetches the weather information from the [Dark Sky](https://darksky.net/dev) API and saves it to the database every minute.
28 | * Node.js, ExpressJS, and VueJS application that fetches the data from the mongo database and displays it in a chart, which is refreshed automatically every minute.
29 |
30 | 
31 |
32 | > Note, the express app is based on https://zellwk.com/blog/crud-express-mongodb/
33 |
--------------------------------------------------------------------------------
/assets/body.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balena-io-experimental/express-mongo-sample/f1a7c9e297977b56fbb3ff8748be50483de33fa4/assets/body.png
--------------------------------------------------------------------------------
/assets/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balena-io-experimental/express-mongo-sample/f1a7c9e297977b56fbb3ff8748be50483de33fa4/assets/header.png
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 |
3 | volumes:
4 | mongo-data:
5 |
6 | services:
7 | mongo:
8 | image: arm64v8/mongo
9 | restart: always
10 | volumes:
11 | - 'mongo-data:/data/db'
12 | expose:
13 | - "27017"
14 | express:
15 | depends_on:
16 | - mongo
17 | build: ./express
18 | ports:
19 | - "80:80"
20 | sensor:
21 | depends_on:
22 | - mongo
23 | build: ./sensor
24 |
--------------------------------------------------------------------------------
/express/Dockerfile.template:
--------------------------------------------------------------------------------
1 | FROM balenalib/raspberry-pi-node:11-buster-run
2 |
3 | WORKDIR /usr/src/app
4 |
5 | COPY package.json package.json
6 |
7 | RUN JOBS=MAX npm install --production --unsafe-perm && npm cache verify && rm -rf /tmp/*
8 |
9 | COPY . ./
10 |
11 |
12 | CMD ["npm", "start"]
--------------------------------------------------------------------------------
/express/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "crud-express-mongo",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "node server.js",
8 | "dev": "nodemon server.js"
9 | },
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "body-parser": "^1.14.2",
14 | "ejs": "^2.3.4",
15 | "express": "^4.13.3",
16 | "mongodb": "^2.1.4"
17 | },
18 | "devDependencies": {
19 | "nodemon": "^1.8.1"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/express/public/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/balena-io-experimental/express-mongo-sample/f1a7c9e297977b56fbb3ff8748be50483de33fa4/express/public/header.png
--------------------------------------------------------------------------------
/express/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |