Coder Social home page Coder Social logo

todolist-api-example's Introduction

Todo List (example app) – Backend API

Backend API for the Todo List example app.

πŸ‘‹ Welcome! This example app is part of this article in the docs for KintoHub to show how you can build cloud native apps in seconds. Head over there to read the guided steps to use this project.

Project structure

This Node.js based backend API app has a dependency on a MongoDB database. It's meant to be used with the Frontend app.

The app uses the hapi framework for handling API routes. It exposes a REST API for persisting Todo items, since the frontend app is based on TodoMVC and relies on this backend for storing the todos.

The REST API has apiDoc annotations, refer to those for usage in app/index.js.

For the purpose of easy debugging, the app logs to the console all API calls and related output.

Configuration

The only thing you must specify is the environment variable that has a connection string to point to the MongoDB database.

Environment variables

  1. MONGODB_CONNECTION_STRING (required) – MongoDB connection string, e.g. mongodb://<user_name>:<password>@localhost:27017/<db_name>?authSource=<auth_db_name>
  2. SERVER_HOST (optional) – host where the server is bound to. Defaults to 0.0.0.0 (all available network interfaces) if undefined.
  3. SERVER_PORT (optional) – port where the server listens on. Defaults to 8000 if undefined.

Usage

Developling locally

You'll need to have a MongoDB database. You could install MongoDB, or if you have Docker Desktop installed, you can spin up a temporary one quickly.

MongoDB with Docker

  1. Once Docker Desktop is installed, you can open create a new MongoDB container:
    docker run --name todolist-mongo -d -p 27017:27017 mongo:4.0
    It will run (detached) a MongoDB 4.0 container todolist-mongo and exposes the default MongoDB port on your localhost.
  2. To confirm whether the container is running, run:
    docker ps
  3. Once you're done, you can quit Docker Desktop or run:
    docker stop todolist-mongo
  4. When you get going again, start up Docker Desktop and run:
    docker start todolist-mongo

Configure environment

To make it easier to specify environment variables for local development, the app uses the dotenv node module to load environment variables from file. You can refer to the example file .env.example, and copy it to a new .env file in the root folder. It's ignored in git.

If you use the MongoDB with Docker method, set your .env file like this:

MONGODB_CONNECTION_STRING=mongodb://localhost:27017/todolist

Run the development server

  1. Install dependencies:
    npm install
  2. Start in debugging mode:
    npm start

Serve in production

For running MongoDB in production, check out the related KintoHub docs article how you can quickly get a cluster going with Helm charts, so it has automatic failover built-in. (you shouldn't run just a single MongoDB instance in a container for production workloads)

Configure environment

Ensure the environment variable MONGODB_CONNECTION_STRING is set, and point to your production grade MongoDB cluster.

You may also want to set the correct SERVER_PORT for exposing the service.

Run the production server

  1. Build the code for a production release:
    npm run build
  2. Serve the built application:
    npm run serve

πŸš€ Deploying on KintoHub

Thank you for checking out this example app. KintoHub makes it super easy to build, deploy, manage and operate your cloud native apps, like this one.

Find out more at www.kintohub.com.

todolist-api-example's People

Contributors

bgever avatar dependabot[bot] avatar

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.