0

After stumbling upon the typscript-node starter released by microsoft, i started to get lost.

Can we really replace node with typescript on the server? There are several serverside things that TS does well: - Creating a web API service with express - Managing the CRUD queries with mongoDB

And much more... I am used to generate an api with node and connect angular to that api. Am i wrong? Should we switch to TS on the backend and forget about writing node code on the server?

2
  • 4
    You cannot replace node with typescript. You would use typescript and node. Typescript transpiles to javascript, and node runs the JS code. (in a very summarized way) Commented Oct 30, 2017 at 1:33
  • 2
    You don't replace typescript with node. They're different technologies that can be used together. Commented Oct 30, 2017 at 1:33

2 Answers 2

1

Typescript is a (or rather, a superset of) language - not a runtime. It is the equivalent of Javascript except it needs to be compiled to run on the Node.js runtime.

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). This is what I do with many projects. It is still "node code", it just has all the benefits (and gimmicks) or Typescript.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. So basically i can write my backend and frontend in TS or ES6 or just plain JS and use node just for runtime
Correct. Just remember you still need to compile your TS-backend-code down to JS (ES6) in order for Node to understand it, just as you need to compile the TS-frontend-code down to JS so that the browser can understand it.
0

I recommend the library meseret to manage your typescript node.js backend code. It has support for Koa, Mongoose and Socket.io, with many builtin configurations. It is a great way to manage things in one place, using TypeScript throughout your project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.