简体   繁体   English

打字稿+节点+快递?

[英]Typescript + Node + Express?

After stumbling upon the typscript-node starter released by microsoft, i started to get lost.在偶然发现微软发布的typscript-node starter 之后,我开始迷路了。

Can we really replace node with typescript on the server?我们真的可以在服务器上用 typescript 替换 node 吗? There are several serverside things that TS does well: - Creating a web API service with express - Managing the CRUD queries with mongoDB TS 在服务器端有几件事情做得很好: - 使用 express 创建 Web API 服务 - 使用 mongoDB 管理 CRUD 查询

And much more... I am used to generate an api with node and connect angular to that api.还有更多......我习惯于用节点生成一个api并将angular连接到那个api。 Am i wrong?我错了吗? Should we switch to TS on the backend and forget about writing node code on the server?我们是否应该在后端切换到 TS 而忘记在服务器上编写节点代码?

Typescript is a (or rather, a superset of) language - not a runtime. Typescript 是一种(或者更确切地说,是一种语言的超集)——而不是运行时。 It is the equivalent of Javascript except it needs to be compiled to run on the Node.js runtime.除了需要编译以在 Node.js 运行时上运行之外,它与 Javascript 等效。

You can write the backend with Typescript if you want, and then run it through ts-node , or just compile down to ES6 via tsc and then run it with standard Node (v8+ is recommended).如果需要,您可以使用 Typescript 编写后端,然后通过ts-node运行它,或者仅通过 tsc 编译为 ES6,然后使用标准 Node 运行它(建议使用 v8+)。 This is what I do with many projects.这就是我在许多项目中所做的。 It is still "node code" , it just has all the benefits (and gimmicks) or Typescript.它仍然是“节点代码” ,它只是具有所有好处(和噱头)或 Typescript。

I recommend the library meseret to manage your typescript node.js backend code.我推荐使用库meseret来管理您的typescript node.js 后端代码。 It has support for Koa, Mongoose and Socket.io, with many builtin configurations.它支持 Koa、Mongoose 和 Socket.io,具有许多内置配置。 It is a great way to manage things in one place, using TypeScript throughout your project.这是一种在一个地方管理事物的好方法,在整个项目中使用 TypeScript。

You can use this node.ts server starter template, it comes with pre configured basic setup for typescript server:你可以使用这个 node.ts 服务器启动模板,它带有预先配置好的打字稿服务器的基本设置:

https://github.com/imReCoder/node.ts-server-starter https://github.com/imReCoder/node.ts-server-starter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM