Git Product home page Git Product logo

express-ts's Introduction

Express.js + TS Template

This repository is meant to be a template to be cloned for future projects for a standard Express.js and Typescript backend server.

Instructions

  • Create copy of repository.
  • Run npm i to install dependancies.
  • Follow Prisma documentation to setup for connection to a DB, if needed.
  • Enjoy!

Scripts

There are scripts for running the build process, starting the server, and running tests. The main ones are provided below.

  • tsc:dev and tsc:prod run the Typescript compiler using the tsconfig.json and tsconfig.prod.json, respectively. Furthermore, the outputs of the two commands are the dev and prod folders, respectively. Prod does not have the test folder in it.
  • alias:dev and alias:prod updates the path aliases in the build output to be correct.
  • build:prod and build:dev run the Typescript compilation and alias correction at the same time.
  • start:prod and start:dev starts the server with the appropriate environment.
  • prod and dev runs the build step and starts the server
  • All options that have watch at the end run the same command but in watch mode.
  • test runs the vitest tests. Note that it does not build.

About Structure

  • The .env and .env.dev are for production and development respectively
  • Folders in the src directory can be imported from by using '@/[folder_name]' (ex. import {a_controller} from '@/controllers/someControllers.js')
  • Imports of local Typescript files must have js or cjs endings due to NodeNext module resolution.
  • Folder structure goes as follows in src
    • controllers are responsible for processing a request, composing services and utils to create a response, and sending the response.
    • middlewares are used for performing actions on every reqeust that hits the app or route it is attached to.
    • models define the shape of entities that are involved in the code.
    • routes are responsible for associating a controller to a set sub route and request method.
    • services are responsible for interfacing with external data providers (ex. database), API's, or other data producing logic that a controller would need.
    • utils are commonly used functions.
    • index.ts is the main file that is ran when server starts
  • Test is split into unit tests and integration tests.

express-ts's People

Contributors

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