6

I searched for this a day now and hope you can help me.

I really like developing JS Applications in TypeScript and I am trying to write my new node application that way. Unfortunately node does not understand TS. Is there a way (besides transpiling to ES5) to start my code directly from the TS file?

In the sad case there is no way to do that, what is the best practice? Writing the app in src/ts/app.ts, transpile it to src/js/app.js and reference this file in the package.json?

2
  • there is no way to run typescript on node without a transpiler. you could try systemjs and live transpiling but I'd advise against it. Commented Sep 1, 2016 at 11:40
  • 1
    You can use TypeScript Node but why would you want to do that? Commented Sep 1, 2016 at 11:45

1 Answer 1

5

Exactly. Simply run tsc before starting your node application. You typically do that by having something like this in your package.json

{ ...
"main": "src/js/app.js",
"scripts": {
    "run": "tsc && node src/js/app.js"
}, ... }

For your further reference, there is a node sample from the official Typescript repositories available here.

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

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.