Giter Site home page Giter Site logo

fr3ndyl33 / expressjs-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from larswaechter/expressjs-api

0.0 1.0 0.0 446 KB

An example Node.js REST-API built with TypeScript & Express.js

Home Page: https://larswaechter.dev/blog/nodejs-rest-api-structure/

License: MIT License

TypeScript 96.00% HTML 0.32% JavaScript 2.47% Shell 0.88% Dockerfile 0.32%

expressjs-api's Introduction

expressjs-api

This repository is a dummy Node.js REST-API built with TypeScript and Express. You might want to use it as codebase for your own Node project.

You can find a detailed explanation about the application's architecture on my blog.

๐Ÿ“Œ Packages

A shortened list of the Node modules used in this app:

๐Ÿ”ฎ Features

  • ACL (access control list)
  • Component-based architecture
  • Caching (Redis)
  • DB seeding
  • Mailing
  • MySQL
  • Testing

๐Ÿ“‚ Folder structure

Read more here.

  • src/api everything needed for the REST API
    • src/api/components component routers, controllers, models, tests and more
    • src/api/middleware API middleware
  • src/config global configuration files
  • src/services services for sending mails, caching, authentication and more
  • src/test test factory

๐Ÿ’ป Setup

Native

Requirements:

Installation:

  1. Run npm install
  2. Rename .env.example to .env and enter environment variables
  3. Run npm run build to compile the TS code
  4. Run npm start to start the application

You can reach the server at http://localhost:3000/api/v1/.

Docker

Requirements:

Installation:

  1. Rename .env.docker.example to .env.docker and enter environment variables
  2. Run docker-compose up to start the Docker containers

You can reach the server at http://localhost:3000/api/v1/.

Building

During the build process the following tasks are executed:

  • Compiling TS into JS
  • Copying mail HTML templates to dist directory
  • Merging component policy.json files into a single one in dist/output/policies.combined.json

The last two tasks are executed using Gulp as you can see in gulpfile.js.

Database seeding

In db/seed.sql you'll find a SQL script that can be used for seeding the database with dummy data. Make sure that the database and its tables were created before executing the script. The tables are created on application start.

You can load the script via a npm command: npm run seed. If you want to seed the database from a Docker container you must connect to it before: docker exec -it expressjs-api bash.

Read more about database seeding on my blog.

๐Ÿ”จ Tools

ACL

This application uses acl for permission management. Each component in src/api/components has its own policy.json which includes permissions for each role.

During the build process all these policy.json files get merged into a single one using a Gulp task as described more above.

MailHog

MailHog is an email testing tool for developers. You can use it as SMTP server to simulate the process of sending mails. MailHog is included as Docker image within the docker-compose.yml file.

Start the containers as described above and you can open the MailHog web interface at http://localhost:8025 where you'll find an overview of all sent emails.

:octocat: Community

expressjs-api's People

Contributors

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