Giter VIP home page Giter VIP logo

dockerize-node's Introduction

Dockerize-Node

A simple RESTful dockerized Node + MongoDB app for adding and retrieving books.

Getting Started (with Docker)

If you have Docker installed in your computer, you do not need to have Node.js or MongoDB installed. You can run the application with a single command:

$ docker-compose up

Getting Started (without Docker)

Without Docker, you need to install Node.js, NPM and MongoDB.
To install Node.js and NPM, refer to the documentation provided here.
To install MongoDB, refer to the documentation provided here.

Step 1 - Start MongoDB

To start MongoDB:

  • Windows:
    $ "C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe"
  • Mac:
    $ mongod --config /usr/local/etc/mongod.conf
  • Ubuntu: Please refer to the documentation provided at the link.

NOTE: Database and collection is automatically created with the first POST request to /api/books. No MongoDB configuration is required after installation - keeping MongoDB running is sufficient.

Step 2 - Start the node server

To get the Node server running locally:

  • npm install to install all required dependencies from package.json:
    $ npm install
  • npm run start to start the local server:
    $ npm run start
  • npm run dev to start the local server in development mode:
    $ npm run dev

Code Overview

Dependencies

  • expressjs - The server for handling and routing HTTP requests.
  • mongoose - MongoDB object modeling tool designed to work in an asynchronous environment.
  • morgan - HTTP request logger middleware for node.js.

Development Dependencies

  • nodemon - The development server that automatically restarts the node application when file changes in the directory are detected.

Application Structure

  • index.js - The entry point to our application. This file defines the express server, integrates all the routes, initializes the logger and the mongoDB connection.
  • src/controller/ - This folder contains the controllers for the app to read and write data to MongoDB.
  • src/routes/ - This folder contains the route definitions for the app.
  • src/models/ - This folder contains the Mongoose Schema definition for the 'books' resource.
  • test/ - This folder contains the POSTMAN collection with all requests configured.

API

Add a new book


Returns json containing newly added data.

  • URL

    /api/books

  • Method:

    POST

  • URL Params

    None

  • Query Params

    None

  • Data Params

    Required:

    • title: [string]
    • author: [string]
  • Success Response:

    • Code: 201 CREATED
      Content: { "id": "abcdefg1234, "title": "Dockerizing your personal projects", "author": "Dhanush Kamath" }

Get all books


Returns json data containing details of all books.

  • URL

    /api/books

  • Method:

    GET

  • URL Params

    None

  • Query Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
      Content: { "books": [ { "title": "Dockerize your personal projects!", "author": "Dhanush Kamath", "createdAt": "2020-12-24T20:59:42.516Z" }, { "title": "Burgers and Cars: An Autobiography", "author": "Dhanush Kamath", "createdAt": "2020-12-24T21:04:27.111Z" } ] }

Authors

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.