GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - probablyArth/typescript-nodejs-zod: template repository for projects using typescript and nodejs.

BranchesTags
Open more actions menu

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
__tests__
__tests__
 
 
src
src
 
 
.dockerignore
.dockerignore
 
 
.env.example
.env.example
 
 
.eslintignore
.eslintignore
 
 
.eslintrc.js
.eslintrc.js
 
 
.gitignore
.gitignore
 
 
.prettierrc.js
.prettierrc.js
 
 
Dockerfile
Dockerfile
 
 
README.md
README.md
 
 
eslint.tsconfig.json
eslint.tsconfig.json
 
 
jest.config.json
jest.config.json
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

server

Template for express, typescript, zod projects.

Glossary

  • Absolute imports

    non-library imports that use absolute path instead of relative.

    for ex:

    .
    ├── apps
    │   └── server.ts
    ├── env
    │   └── index.ts
    ├── folder1
    │   └── folder2
    │       └── a.ts
    ├── index.ts
    └── middlewares
        └── logger.middleware.ts
    
    // folder1/folder2/a.ts
    
    // this is a relative import
    import { getEnv } from '../../env/index.ts';
    
    // this is an absolute import
    import { getEnv } from 'env/index.ts';

Features

  • support for absolute imports in both development and build using tscpaths and tsconfig-paths
  • zod for validating .env vars.
  • dotenv for parsing .env files.
  • morgan for logging.
  • jest and supertest for tests.
  • express for http server.
  • prettier for formatting.
  • eslint for linting and forcing code styles.

How-to(s)

  • How to use absolute imports

    Absolute imports are not resolved by the default typescript build tool, tscpaths takes care of it.

    if you want to create imports from a folder let's say src/folder1 and name it folder1

    add this entry in the tsconfig.json

    {
      //tsconfig.json
      "compilerOptions": {
        //...rest of the config
    
        "paths": {
          //..other paths
    
          "folder1/*": ["folder1/*"],
        },
      },
    }

    you don't need to mention src/folder1/* because the baseUrl is set to ./src which is changeable in the tsconfig.json

    //tsconfig.json
    {
      "compilerOptions": {
        "baseUrl": "./src", // <--change here
      },
    }
  • How to add env vars to the pre-existing zod schema

    just add the key in the envSchema object in ./src/env/index.ts and give it the value of z.string()

    // ./src/env/index.ts
    .
    .
    .
    .
    
    const envSchema = z.object({
      // other variables
      yourKey: z.string(),
    });

setup

  • Install the dependencies

    npm i
  • create a .env file from .env.example

    cp .env.example .env

Running the server

  • Follow the instructions mentioned in setup

  • for development server

    npm run dev
  • for running production build

    npm run build && npm start
  • using Docker

    builidng docker image

    docker build -t <image_name> .

    running docker image

    docker run -e PORT=4000 -p 4000:4000 <image_name>
    
    Note: PORT is an env variable

Running tests

npm run test

Linting

npm run lint

About

template repository for projects using typescript and nodejs.

Resources

Readme
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.