/express-ts

Primary LanguageJavaScript

Express + TypeScript Application Starter Code

This code sets up an Express.js app with minimal TypeScript support.

Installation

  1. Download the code as a .zip archive.
  2. Extract the archive's contents into a new folder named, for example, myapp. (This is the name currently specified in package.json.)
  3. In package.json and in bin/www (which is actually a JavaScript file), replace myapp with the name of your application folder.
  4. Create a new file named .env in the root folder with the following initial content:
    # Replace myapp with the name of your application
    DEBUG=myapp:*
  5. Run npm install in the root folder.

Usage

npm start compiles your .ts sources and invokes nodemon on the generated .js files.

Folder Structure

πŸ“¦ 
β”œβ”€ .env                  # definitions of environment variables. Excluded from Git repo.
β”œβ”€ .gitignore
β”œβ”€ bin
β”‚  β””─ www                # startup code
β”œβ”€ package-lock.json
β”œβ”€ package.json          # npm package configuration
β”œβ”€ public                # static assets
β”‚  β”œβ”€ index.html
β”‚  β””─ stylesheets
β”‚     β””─ style.css
β”œβ”€ src                   # TypeScript source tree root
β”‚  β”œβ”€ app.ts             # main application file
β”‚  β””─ routes             # Express routers. The folder hierarchy should reflect the hierarchy of your REST API endpoints.
β”‚     β”œβ”€ index.ts
β”‚     β””─ users.ts
β”œβ”€ tsconfig.json         # TypeScript configuration
└─ views                 # Jade templates. Remove this folder and all references to it in `app.ts` if you intend to use a frontend framework like React.
   β”œβ”€ error.jade
   β”œβ”€ index.jade
   β””─ layout.jade

Β©generated by Project Tree Generator