5

I am building a skeleton MEAN project using the Angular CLI. Here is a look at the folder structure and the tsconfig.json file.

enter image description here

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.

1 Answer 1

3

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:

enter image description here

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"
Sign up to request clarification or add additional context in comments.

3 Comments

Have you found a better solution, as I'm experiencing the same problem?
Nah, that's the solution I'm using; a separate config file for the server code.
can i get your repo i am near to run both on single

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.