Giter Club home page Giter Club logo

nodemongoopenshiftbackend's Introduction

Deploy an ExpressJS/MongoDB Api on OpenShift

This repo contains starter code to deploy a nodeJS ExpressJS API on OpenShit. If followed correctly you will have CRUD endpoints on collections within MongoDB

Pre reqs

  1. Connected to campus VPN
  2. Github Account, you can use GitHub's code editor to change the MongoDB IP address later on
  3. Sign up for Carolina Cloud Apps | This step will only take a second
  4. Fork this repo to your github account

Create a MongoDB database

  1. Head to the Topology Tab under the Developer View
  2. Select Database from the tiles that appear
  3. Select MongoDB from the tiles that appear and hit instantiate template on the modal that opens
  4. Accept all default values in the form, for the purpose of this demonstration you can use email and password settings as follows. Please make sure you remember or note these values as you will need them later
    Database Config
  5. Hit create
  6. Once the status of the pod shows up as active, head to the resource tab, and then hit view logs on the pod, followed by the terminal tab
    View Logs
  7. In the terminal type the following command
mongo -u "admin" -p "Admin123" admin
  1. If the connection is successful you should see this in the terminal
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017/admin
MongoDB server version: 3.6.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
  1. Go back to the topology and click the mongodb pod, from there hit the mongodb service
    Database Service
  2. Note the IP of the cluster, and update the IP address of the database connection in this repo under config/database.config.js
    IP Address

Deploy the ExpressJS app

  1. Head to the Topology tab under the Developer view
  2. Right click anywhere and select add to project from catalog
  3. Search nodeJS and hit the first tile and hit create application
  4. Provide the Github repo link of your forked repo, this repo should contain the updated IP of your mongodb database
    Node Config
  5. Hit Create, click on the newly created pod, and wait for the build to finish
  6. Visit the endpoint, by clicking the link on the pod
    Link
  7. if you have followed all steps correctly you should see the following output in the browser
{"welcome":"This is a backend starter api based on an express api connected to mongodb, on the OpenShift container platform"}
  1. Congratulations your API is now live, modify the routes and model for your use case. Default CRUD implementations have been provided under app/controllers and you can play around with them in Postman.

Additional Tools and Tips

  1. Download MongoDB Compass, use this to remotely connect to the DB. You can use the same connection string as in the database config
  2. Download the OpenShift CLI, can be used to emulate pods and route ports for local testing
  3. Heres how to remotely connect to MongoDB over localhost
oc get pods

This will return output like

NAME                     READY     STATUS       RESTARTS   AGE
mongodb-1-XXXXX          1/1       Running      0          12h
my-node-app-10-build     0/1       Completed    0          10h

Grab the mongodb pod name from the output. From here you can remote sh using the following command

oc rsh mongodb-1-XXXXX

To connect to mongodb via local host setup port forwarding, this will allow you to send traffic to mongodb over localhost:34000. You can also replace the ip in the database config with localhost:34000 to test connections locally

oc port-forward mongodb-1-XXXXX 34000:27017
  1. Enable SSL, ssl can be enabled in Administrator view by going to Networking, Routes, name of your node application, and adding this tls argument to your YAML configuration under the spec section
tls:
    termination: edge
    insecureEdgeTerminationPolicy: None

nodemongoopenshiftbackend's People

Contributors

rahulunc avatar

Watchers

 avatar

Forkers

samlempp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.