GithubHelp home page GithubHelp logo

typescript-express's Introduction

使用 typescript + express 创建 NodeJs 后端服务

初始化 NodeJs 程序

npm init -y

安装依赖

pnpm add express
pnpm add ts-node nodemon @types/node @types/express -D

配置 nodemon

在根目录创建nodemon.json来配置 nodemon:

{
  "watch": ["./"],
  "ext": ".ts,",
  "exec": "ts-node app.ts"
}

配置启动脚本

package.json 中配置启动脚本:

{
  // /
  "scripts": {
    "dev": "nodemon"
  }
  ///
}

由此,一个 typescript 版本的 NodeJs 工程就搭建好了。然后就开始安装 express 等依赖,来写业务代码了。

问题记录

使用 express-async-errors 处理异步错误

描述:如果我们用 async 和 await 去拦截代码错误,需要使用 try catch 去拦截错误,每个接口都这样去做太麻烦了,因此使用 express 本身的错误处理加上第三方库 express-async-errors 来处理: 使用文档:官方文档, CSDN

// app.ts
require("express-async-errors");

typescript-express's People

Contributors

rondout avatar

Stargazers

 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.