Skip to content

πŸ‘¨β€πŸ’» A sample API with Node.js + TypeScript in the mongoDB

Notifications You must be signed in to change notification settings

Lucasbrunoferreira/nodejs-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Express REST API - Node.JS + TypeScript

License: MIT node TypeScript

Structure for node.js projects involving typescript

Getting Started

Hello, my name is Lucas Bruno, and I am providing this framework, which has been very helpful to me during the development of REST APIs using Node.js and TypeScript. Hope you enjoy, any feedback and pull request is very welcome!

Prerequisites

In order to use this project, you must have the following requirements:

  • NODE
  • NPM

Structure

Project structure:

β”œβ”€β”€ src
β”‚   β”œβ”€β”€ api               ---> The Folder to handler API layers
β”‚   β”‚   β”œβ”€β”€ controllers   ---> Input and Output of the application, along with basic request validations.
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ middlewares   ---> Request Interceptors
β”‚   β”‚   β”‚
β”‚   β”‚   └── routes        ---> App route settings
β”‚   β”‚
β”‚   β”œβ”€β”€ config            ---> Application Settings, Logging, Environment, Express middleware ...
β”‚   β”‚
β”‚   β”œβ”€β”€ interfaces        ---> Implementation of interfaces for development assistance
β”‚   β”‚
β”‚   β”œβ”€β”€ models            ---> Models, Entities and Schemas for manipulation and persistence.
β”‚   β”‚
β”‚   β”œβ”€β”€ persistence       ---> Definitions and database instances.
β”‚   β”‚
β”‚   └── services          ---> It gathers business rules and external manipulations (Database, other api's ...)
β”‚
β”œβ”€β”€ tests                 ---> Unit Tests

Installing and Running

So you can run your project in your environment, follow these steps:

Clone the project in your preferred folder.

cd nodejs-rest-api
npm install
npm run dev

And ready! The application will be running on the port defined in src/server.ts

Running the tests

This application has unit tests using the Jest framework.

To run unit tests:

npm run test

To run unit tests with coverage:

npm run coverage

And coding style tests

So that we can write cleaner and more beautiful code, we can adopt linear frameworks like Eslint.

npm run lint

Deployment

If you want to enjoy the application in production, you can use the Docker.

For this, the project has the Dockerfile configuration file, so that it can generate the project image.

docker build --name nodejs-api .
docker run -d -p 8080:8080 nodejs-api

Built With

  • Express - The web framework used
  • TypeScript - Is a Typed superset of Javascript
  • Mongoose - Elegant mongodb object modeling for node.js
  • Jest - Is a delightful JavaScript Testing Framework
  • Eslint - The pluggable linting utility for JavaScript
  • EditorConfig - Helps maintain consistent coding styles

References

  • Santiq - Bulletproof node.js project architecture
  • RocketSeat - Project code produced during TypeScript video on NodeJS

Authors

About

πŸ‘¨β€πŸ’» A sample API with Node.js + TypeScript in the mongoDB

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published