Skip to content

A NodeJs application written in TypeScript using ExpressJs framework to create a RESTful api for User model data stored in MongoDB using Mongoose as an adapter. Using the tsoa tool to facilitate a Swagger UI browser API test portal.

Notifications You must be signed in to change notification settings

WillStreeter/ws-node-demo

Repository files navigation

ws-node-demo

A NodeJs application written in TypeScript using ExpressJs, Mongoose, and tsoa to stand up the Swagger UI.

Prominent Libraries used:

Architecture:

The article Swagger, NodeJS, & TypeScript : TSOA, has a deeper review of how this application is constructed. This back-end application is a part of a larger effort to demonstrate the principals of web development expressed in the article Practical Web Development and Architecture. Advocating the principal "a separation of concerns", thin controllers residing in the "service-layer" retain the singular purpose of acting as filters for API request. Controllers exist to support results of data processing logic derived in outside layers of concern. Maximizing the opportunity for application growth, without extensive refactoring, the processing of business rules and cross-cutting concerns are placed in the "business-layer", while database adapters, formalized data base queries, and services used to abstract those queries are stationed in the "data-layer". As much as possible the controllers duties are focused on directing request to outside resources and responding to results from those resource with simple conditional logic.

Another aspect emphasized in the Practical Web Development and Architecture article is the importance of adopting strategies to support optimal output from a development team. To this end tsoa, a Swagger UI creation tool, is used to demonstrate an innovative means of generating an API testing portal and documentation based on a few simple structural requirements. The Swagger scaffolding resides in the "presentation-layer" .

ws-dev-docker-example : is the repository used to bundle this application along with three other submodules. Docker compose is used to orchestrate the development of a FullStack. Those submodules are located in the GitHub repositories listed below.

How these containers are used as a bundle to facilitate a FullStack approach for developing with Docker is delineated in the article, Docker is my {I.D.E}

It should be noted that this application is created for the purposes of demonstrating a development paradigm, not as a production ready seed.

Although the application is best understood as a part of the larger overall effort demonstrated with the ws-dev-docker-example, it can still be cloned and stood up without the use of the Docker bundle. To use this application as a separate standalone entity, use the local-client branch.

Ways to construct this application with or without Docker

  1. Using the FullStack( This NodeJs app, Mongo, NGINX, Angular app ) approach with an integrated Docker environment.

  2. Using Docker to stand up the application with a dependency of Mongo


   $> git fetch

   $> git checkout origin/serverless

   $> docker-compose up

  1. BareMetal (Installing libraries and running it on your machine's OS)


   $> git fetch

   $> git checkout origin/local-client

   $> npm install

Befor running the application, you will need to update the src/data-layer/adapters/MongooseAccess.ts file by switching commented outline 21 and 22.

from

 //let connectionString =   config.get('mongo.urlClient').toString();
  let connectionString = config.get('mongo.urlDocker').toString();

to

   let connectionString =   config.get('mongo.urlClient').toString();
  //let connectionString = config.get('mongo.urlDocker').toString();

Making this change will switch the host from ws-mongo-demo to 127.0.0.1 (localhost). These variables are set in the config/default.yaml

   $> npm run start

Here are some examples of object types to insert an incorrect user and a correct user


  {
    "username": "tao",
    "password": "1234",
    "firstname": "zip",
    "lastname": "zap",
    "email": "[email protected]",
    "admin": false,
    "isLoggedIn": false
  }


  correct user
  {
    "username": "taosing",
    "password": "password",
    "firstname": "fifty",
    "lastname": "cents",
    "email": "[email protected]",
    "admin": false,
    "isLoggedIn": false
  }

About

A NodeJs application written in TypeScript using ExpressJs framework to create a RESTful api for User model data stored in MongoDB using Mongoose as an adapter. Using the tsoa tool to facilitate a Swagger UI browser API test portal.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published