typescript-koa-postgresql 实现一个简单的rest风格服务器 —— typescript 开发环境配置...

最近需要用 nodeJS 写一个后台程序,为了能够获得 IDE 的更多代码提示,决定用 typescript 来编写,随便也学习下 ts,在这记录下实现过程。

1、新建文件夹 typescript-koa-postgresql,初始化项目

yarn init -y

2、安装 typescript

yarn add typescript @types/node --dev

3、配置  typescript 编译环境,在项目根目录下新建文件 tsconfig.json 

 1 {
 2   "compilerOptions": {
 3     "target": "es2017",
 4     "outDir": "./dist",
 5     "module": "commonjs",
 6     "emitDecoratorMetadata": true,
 7     "experimentalDecorators": true,
 8     "lib": [
 9       "es6"
10     ],
11     "noImplicitAny": false,
12     "sourceMap": false,
13     "allowJs": true
14   },
15   "include": [
16     "./src/**/*"
17   ],
18   "exclude": [ 
19     "node_modules" 
20   ] 
21 }

4、测试  typescript 环境,新文件夹 src 并添加文件 server.ts 

console.log("Hello TypeScript");

 在 package.json 中加入

"scripts": {
     "build": "tsc"
 }

运行 

yarn run build
node ./dist/server.js

输出

Hello TypeScript

至此  typescript 环境 配置完成

 

目录结构如下:

转载于:https://www.cnblogs.com/lifefriend/p/10020831.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值