Coder Social home page Coder Social logo

basic-ts-template's Introduction

Project Template

Here's a basic typescript + express + prisma project template for learning purposes. I'll try to explain a few decisions here.

Tooling

We're using typescript here because it greatly helps code maintainability. Ts-node-dev is used for development so we can get live reloading as we develop. When we go to production we will have to run a build script and run from node for performance improvements. I would like to look into Deno in the future instead as it is Typescript native and has some really interesting features.

Our database is Prisma (prisma.io). It is in my opinion the easiest and best way for JS side projects and startups to work with a database. Prisma not only acts as a great type-safe ORM but also handles all database migrations as well. We only have to modify the schema.prisma file and it will automatically generate SQL files to upgrade our database.

Prisma requires some work to have it working on your machine. When you pull down the project you will have to run npx prisma db push to sync your database. This isn't recommended by Prisma as it doesnt generate migration files but it does force your database to sync with the schema file which is useful for development.

After modifying your schema file you will have to run yarn generate to update the Prisma client.

Further documentation should be found at Prisma's website.

Server

I'm using express for the server here. It is a tad outdated now by Node standards but still has a large and vibrant community around it. You shouldn't have any trouble finding middlewares and examples for it. The server is bootstrapped in src/server.ts and routes are imported from the routes/ folder. I've tried to set this up in a basic MVC architecture - you can think of the route files as controllers.

Testing

Jest is the standard for JS testing nowadays and this project is no different. I expect to write tests in the tests/ folder that mirror the other files in the project. That is to say, for the routes/posts.routes file we will have a tests/routes/posts.routes.test file to test it. I'm still working on examples for this.

basic-ts-template's People

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.