node.js创建server服务---sublime 的node及typescript环境配置

一.初始环境搭建

mkdir server //创建server文件夹
cd server //进入到创建的文件夹目录下
npm init -y //生成含有默认配置的package.json文件
npm install @types/node --save //配置node的类型定义文件
npm install express --save //安装express
npm install @types/express --save //安装express的类型定义文件server目录下新建tsconfig文件
npm install -g typescript //配置typescript开发环境,没有安装typescript需要全局安装

sumblime Text3下,配置Tools/Build System/New Build System里写入文件

{
    "cmd": ["tsc","$file"],
    "file_regex": "(.*\\.ts?)\\s\\(([0–9]+)\\,([0–9]+)\\)\\:\\s(...*?)$",
    "selector": "source.ts",
    "osx": {
        "path": "/usr/local/bin:/opt/local/bin"
    },
    "windows": {
        "cmd": ["tsc", "$file"]
    }
}

保存为TypeScript.sublime-build, Build System设置为Automatic, ctrl+B编译ts文件,会自动生成对应的js文件

二.入门小例
1. 初始化server服务,建立hello_server.ts文件
2. 命令行输入 `tsc server/hello_server.ts`,生成对应的hello_server.js文件
3. 命令行启动8000端口,node server/hello_server.js,打开`localhost:8000`,可以看到`hell node!`

项目地址 https://github.com/leitingting08/server

posted @ 2018-04-05 14:03  c-137Summer  阅读(260)  评论(0编辑  收藏  举报