I am building a skeleton MEAN project using the Angular CLI. Here is a look at the folder structure and the tsconfig.json file.
Right now, the server code, in the server directory, is written in JavaScript and I would like to be able to write it in TypeScript.
In development, I usually run the following commands:
nodemon server.js
ng build --watch
I am wondering what changes do I need to make in order to be able to write my server code in TypeScript? Do I need to create a separate tsconfig.json file somewhere else to deal with the server code or can instructions for Angular and server code be contained in the same tsconfig.json file? Can I keep using the 2 above commands for my development? Do I need to add a new command? Ideally, I would prefer a solution that doesn't use tools like Gulp but sticks to NPM scripts, if need be.
Here is my solution. I have added a second tsconfig file in the root directory that I named tsconfig-server.json. Here is a look at the content of this file:
What's more, I have changed my NPM start script to run the following:
"start": "ng build -watch | tsc -p tsconfig-server.json -watch | nodemon server.js"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With