Skip to content

peterruler/mongo-arm

Repository files navigation

Mongodb & Mongoose Nodejs Backend on ARM Processors

Demo

Description

  • This is a Nodejs mongodb REST backend that uses docker / docker compose and shows optional deployment to oracle free tier cloud server

Prerequisites

Build

  • in a terminal cd to this projects directory.
  • sudo docker compose --build

Start containers in detached / background mode

  • sudo docker compose up -d

Verify connection

  • sudo docker exec -it database_container mongosh --authenticationDatabase admin -u root -p example
  • show dbs;

Test

  • call localhost:3000 in a webbrowser in the swagger-docu and use the payload:
  • { "id": 1, "client_id": "2222", "title": "Bar", "active": false }
  • choose post projects add payload in the textfield and hit execute! A status code 200 should result!

Stop & delete docker containers

  • sudo docker compose down -v

Tutorial on use mongodb in docker in a good explanation:

Tutorial to install oracle free tier cloudserver - best free setup

SSL support

Deployment to stage server

  • VERY IMPORTANT: during the installation on your oracle cloudinstance - you first get your ssh key - copy it & save to your local machine and store it in the /Users/<username>/.ssh folder
  • install git on server sudo apt-get install git
  • the do a git clone https://github.com/peterruler/mongo-arm.git
  • you will need ssh (digital ocean has great tutorials on the topic) login to the servers console & scp (google for it) or git (install git on server and clone repo) to get your data on the server
  • ssh <username>@<IP> see stackoverlow on how to add key
  • upload data from local console to server (opional):
  • scp -i /localmachine-pathtokey/ssh.pub -r /localmachinepath/mongo-arm <username>@<IP>:/home/<username>/

Install docker on stage server

Following code is for deployment on stage server e.g. on oracle free tier

Installation Notes for Ubuntu Server

sudo apt-get remove docker docker-engine docker.io

sudo apt-get update

sudo apt install docker.io

sudo apt install docker-compose # is different to macos

sudo systemctl start docker

docker-compose command is different to the one on macos

sudo docker stop mongo-arm-web-1

sudo docker rm mongo-arm-web-1

sudo docker-compose --build

sudo docker-compose up -d # instead of sudo docker compose up

docker exec -it database_container bash

docker compose

#!/bin/bash
sudo docker-compose build
sudo docker-compose up -d # note this is different to macos m1
sudo docker ps
sudo docker inspect database_container
sudo docker exec -it database_container bash
show dbs;
use myFirstDatabase;
show collections;
db.users.find();
db.issues.find();
db.projects.find();

Docker Compose file

version: '3'
services:
  mongo_db:
    container_name: database_container
    image: mongo:latest
    restart: always
    ports:
      - "27017:27017"
    volumes:
      - mongo_db:/data/db
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=example
  web:
    build: .
    ports:
    - 3000:3000
    environment:
      MONGODB_URI:  mongodb://root:example@mongo_db:27017/myFirstDatabase?authSource=admin
      PORT: 3000
      NODE_ENV: production
    depends_on:
    - mongo_db
volumes:
  mongo_db: {}

Dockerfile

FROM node:alpine

# Create app directory
WORKDIR /usr/src/app

# Co0py dependencies 
COPY package.json ./
COPY package-lock.json ./

# Install dependencies 
RUN npm install

# Bundle app source
COPY ./app ./app
COPY ./.env ./
COPY ./server.js ./
COPY ./swagger.json ./

EXPOSE 3000
CMD [ "npm", "start" ]

Alternatively

Improved with ♥ by Pete in 2025

enjoy & have fun!

About

My REST Backend to several of my react native / expo, vercel, render, etc. frontends

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published