How to run a TypeScript file from the Command line?

How To Run A Typescript File From The Command Line?

Are you having hassle with the “How to run a TypeScript file from the Command line” downside? If sure, don’t miss this text! We gives you some options to remedy this downside. Read on it.

What can we do to run a TypeScript file from the Command line?

Solution 1: Launch node filename.js to run the created js file

TypeScript will create a js file with the identical identify at runtime once you execute tsc filename.ts. Launch node filename.js to run the created js file.

The creation of a TypeScript file named helloworld.ts and a few content material. To launch helloworld.ts, run the instructions proven under.

tsc helloworld.ts
node helloworld.js

It gives you the consequence:

whats up world from typescript file

Solution 2: Utilize the ts-node bundle

You can also make the most of the ts-node package to run a TypeScript file from the Command line.

First, run the following command to set up the ts-node bundle with npm or some other bundle managers.

Then, run the TypeScript recordsdata with this command:

Please run the following command to execute the identical file that we tried in answer 1.

It gives you the consequence:

whats up world from typescript file

Solution 3: Combine each instructions with a pole | and &&

You can also execute a TypeScript file from the command line by combining each instructions with a pole | and &&, as proven under:

READ :  Unexpected Token ‘Export’ Error In Javascript – How To Fix It?

For Linux or MacOS:

tsc helloWorld.ts && node helloWorld.js

For Windows:

tsc greet.ts | node greet.js

Conclusion

We hope you take pleasure in our article about the downside “How to run a TypeScript file from the Command line”. Whenever you might have points or any questions, please depart your remark under. UnliHow is all the time right here to enable you to. Thank you to your studying!

Read extra

How to Convert a String to a Date object in TypeScript

pymysql Error: File “/usr/local/lib/python2.7/site-packages/PyMySQL-1.0.2-py2.7.egg/pymysql/connections.py”, line 167 SyntaxError: invalid syntax

raceback (most up-to-date name final): File "log2user-real.py", line 49, in <module> db = create_engine("mysql+pymysql://root:{m_pass}@10.157.2.25:8306/log_user?charset=utf8".format(m_pass=m_pass)) File "<string>", line 2, in create_engine File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/deprecations.py", line 309,...
Avatar Of Budi Setiawan Budi Setiawan
31 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *