Coder Social home page Coder Social logo

wesrobinson12 / node-es6-rest-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from archfirst/node-es6-rest-template

0.0 0.0 0.0 291 KB

A template to kick-start Node.js projects using ES6 and RESTful API best practices

JavaScript 97.75% Dockerfile 2.25%

node-es6-rest-template's Introduction

Node ES6 REST Template

The purpose of this template is to kick-start your Node.js projects using ES6. It implements best practices in developing RESTful APIs and Domain-Driven Design. Features include:

  • Use of the Hexagonal Architecture to arrange the application into logical layers, with well-defined responsibilities.
  • RESTful APIs are implemented using the Express framework.
  • Persistence is implemented using an in-memory repository layer. This can be substituted with any persistence technology of your choice.

Dev Build

$ npm install
$ npm start

The dev build starts the application in watch mode. If you make any changes to the source files, the application will recompile and restart.

To verify that the application is working correctly, point your browser to http://localhost:8080/api/books/design-patterns - you should see a response with one books in JSON format.

You can see a OpenAPI (Swagger) definition of the REST API at http://localhost:8080/api-docs/. This interface also allows you to interact with the API.

To debug the application in Chrome, point the browser to chrome://inspect and click on "Open dedicated DevTools for Node".

Production Build

$ npm run build
$ npm run serve

Docker Build

$ docker build -t <dockerhub_username>/node-es6-rest-template:1.0.0 .
$ docker run -d --rm --name rest-server -p 8080:8080 <dockerhub_username>/node-es6-rest-template:1.0.0

Folder Structure

/src
    /routes
    /services
    /repositories
    /utils

The source folder contains sub-folders that arrange the application into logical layers as suggested by the Hexagonal Architecture (a.k.a. the Onion Architecture):

  • routes: This is the adapter layer of the Hexagonal Architecture. It adapts the HTTP transforms the HTTP requests from the external world to the service layer and transforms the objects returned by the service layer to HTTP responses.

  • services: The service layer coordinates high-level activities such as creation of domain objects and asking them to perform tasks requested by the external world. It interacts with the repository layer to save and restore objects.

  • repositories: The repository layer is responsible for persisting domain objects and performing CRUD operations on them. This template uses in-memory persistence, however it can be easily replaced to use a relational or NoSQL database.

  • The utils folder contains useful utilities and helpers.

node-es6-rest-template's People

Contributors

nareshbhatia 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.