In this article, we use a different way to create the project.
Here we create a folder as the project directory in advance
and then open the project terminal and enter
npm init
Then in the new dialog box that pops up, just write a random name and press Enter. Enter yes in the last one and press Enter.
This way we have a basic node project structure.
Then we introduce the TS dependency globally and
enter the terminal.
npm install -g typescript
Then open the command window as an administrator and
execute the terminal
tsc --init
In this way, we have a ts configuration file
and there are two pieces of information here: outDir, the output directory information rootDir, and the source code path.
You can refer to my configuration. Of course, you can also modify it according to your actual situation. Anyway, this is all defined by yourself.
Then we We need to create these two directories corresponding to our own configuration.
Then we create an index.ts in the src directory. The content is as shown below.
Then we add a command to the scripts of package.json.
"start": "tsc && node out/index.js"
Then we run the terminal
npm start
Here our content is output in the terminal, and here ts also helps us parse it using js syntax.