GithubHelp home page GithubHelp logo

express-typescript-starter's Introduction

Express + TypeScript

Express + TypeScript Starter

This repository provides a quick and easy starting point for building web applications using Express.js and TypeScript. With this starter, you can quickly set up a server-side application with strong typing, making it easier to build and maintain robust APIs and web services. Whether you're new to TypeScript or just looking for a solid foundation for your Express project, this starter will save you time and effort.

Features

  • Express.js server with TypeScript support
  • Structured project organization
  • Environment variables using dotenv
  • Pre-configured linting and formatting (ESLint, Prettier)
  • Basic example routes for quick testing
  • Nodemon for automatic server restarts during development
  • Unit testing setup with Jest and Supertest

Prerequisites

Before you get started, make sure you have the following installed:

Getting Started

  1. Clone the repository:
git clone https://github.com/your-username/express-typescript-starter.git
  1. Change into the project directory:
cd express-typescript-starter
  1. Install the dependencies:
npm install

Manually

  1. Initialize package.json
   yarn init -y

or,

     npm init -y
  1. Initilize tsconfig.json
  tsc --init
  1. Edit the tsconfig.json
{ "compilerOptions": { "target": "ES6" , "module": "commonjs" , "rootDir": "./src" , "moduleResolution": "Node" , "outDir": "./dist" , "esModuleInterop": true , "forceConsistentCasingInFileNames": true , "strict": true , "skipLibCheck": true }, "include": ["src/**/*.ts"], "exclude": ["node_modules"] }
  1. Install packages

Install dev dependencies

yarn add typescript @types/node @types/express nodemon -D

Install Dependendcies

yarn add express
  1. Create a .env file in the root of the project and set the required environment variables. You can use the provided .env.example file as a template.

  2. Build and start the server:

npm run build
npm start

The server should now be running on http://localhost:3000.

Project Structure

The project structure follows a modular organization, separating concerns to enhance maintainability and readability. Below is a brief overview of the directories:

  • src: Contains the main source code.
    • controllers: Define route handlers and interact with the data models.
    • middlewares: Custom middleware functions.
    • models: Data models (e.g., database schemas).
    • routes: Express route definitions.
    • app.ts: Entry point of the application where the Express app is set up.
  • test: Contains the unit tests.
    • controllers: Test suite for the controllers.
    • utils: Reusable testing utilities.
  • dist: Output directory for compiled TypeScript code (automatically generated).

Running Tests

To run the unit tests, use the following command:

npm test

Development Workflow

During development, you can take advantage of Nodemon for automatic server restarts on file changes. Use the following command to start the server in development mode:

npm run dev

Contributing

We welcome contributions to improve this starter. If you find any issues or want to add new features, feel free to create a pull request. Additionally, if you encounter any bugs or have suggestions, please open an issue.

License

This project is licensed under the MIT License.


Happy coding! If you have any questions or need further assistance, feel free to contact us.

express-typescript-starter's People

Contributors

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