Giter Site home page Giter Site logo

wvides / express-api-with-mongo-template Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 52 KB

This is a generator template for express RESTful APIs with Mongo to be used with ironman generator https://github.com/ironman-project/ironman

JavaScript 97.84% Dockerfile 2.16%

express-api-with-mongo-template's Introduction

Ironman Express API with mongo generator template

This is a template to generate Express RESTful APIs that use mongo db. It uses ironman generator https://github.com/ironman-project/ironman

Installing this generator

  1. Install ironman https://github.com/ironman-project/ironman#install
  2. Install this generator
ironman install https://github.com/omarvides/express-api-with-mongo-template.git

Defining your variables

Create a yaml file with the parameters of the generator it could be a file named values.yaml containing the variables that the template expects

example.yaml

projectName: Some Project Name
projectDescription: Some project Descript

This repository expected variables, to write your own instance of the file above, you can copy following snippet, write it down in a yaml file and modify it to meet your needs.

variables.yaml

version: 1.0.0
description: "This api is useful"
author: "User Name <[email protected]>"
license: "MIT"
api_name: "example-api"
dbhost: "localhost"
dbuser: "root"
dbpassword: "root"
dbport: "27017"
nodeport: "4000"

Variables reference

Variable Description Default value
version The current API version something like 1.0.0 this will be written a the package.json file 1.0.0
description A brief description of the API, this will be added to the package.json file
author Name and email of the API author, will be added to package.json
license License to be written at the package.json for the app (MIT, GPL, etc) MIT
api_name The api name, must be a string separated with dashes (lower kebab case) rest-express-mongo
dbhost The host for the mongo database (example: localhost)
dbuser The user of the mongo database (example: root)
dbpassword The password of the mongo database (example: root)
dbport The port of the mongo database (example: 27017)
nodeport The port which the API will use to listen to requests 3000
docker_user The usarname on dockerhub or the docker registry to use docker_user
docker_image The image of the docker image to publish to docker_image

Using it

Without a variables file

ironman generate express-api:api /directory/to/create/your-api

With a variables file defined

ironman generate express-api:api /directory/to/create/your-api -f variables.yaml

Getting started with your new API

  1. Move to your api directory
cd your-api-name
  1. Install the dependencies
yarn install
  1. Run a mongo instance, you can use docker-compose and the following docker-compose.yml file
version: '3'
services:
  mongo:
    image: mongo:3.7
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=root
    ports:
      - "27017:27017"
  1. Update your .env file, if using above docker-compose update it to
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=root
DB_PORT=27017
  1. Start your api
yarn start

Builds

This generator creates repositories with a .drone.yml file.

If you are tracking this repository with a drone CI server, it will automatically start building the first time you push your code, and will have buils for any commit at any branch you create, you can also add your favorite CI tool configuration files.

.drone.yml file content:

pipeline:
  backend:
    image: node
    environment:
      - DB_HOST=database
      - DB_USER=root
      - DB_PASSWORD=root
      - DB_PORT=27017
    commands:
      - sleep 15
      - npm install
      - npm test
      - npm run integration
    docker_publish:
      image: plugins/docker:17.12
      repo: docker_user/docker_image
      dockerfile: docker/Dockerfile
      auto_tag: true
      secrets: [docker_username, docker_password]
      when:
        event: [ tag ]
services:
  database:
    image: mongo:3
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=root

The .drone.yml file contains a service configuration to provide a docker container with a mongo database version 3 and sets some environment variables to guarantee that your api integration specs will be able to find and connect to the database.

This version of the .drone.yml file will also publish to a docker registry the application on a docker container, by default it will publish the image when the repository is tagged, with the version of the tag, if the repository is tagged with 1.0.0 it will create the tags 1.0 and 1 and push them to the docker registry being used, by default dockerhub, when the repository is merged to master from a branch the pipeline will create the latest tag and push it to the registry.

Start coding :)

express-api-with-mongo-template's People

Contributors

wvides avatar

Watchers

 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.