Rohan Agarwal
Rohan Agarwal

Reputation: 2609

How to update the content of a nodejs file?

Suppose I have a file abc.ts having the following content

... // some other content

switch(item) {
case 1: break;
case 2: break;
.
.
. 
case x: break;
default: break;
}

...

export const someOtherUnrelatedVariable = 'Help me out';

...

Now I have another file change.ts that needs to add more case statements in the switch case clause in abc.ts programmatically.

I want to achieve it using NodeJS only. Can I do it?

Upvotes: 0

Views: 355

Answers (1)

Bergi
Bergi

Reputation: 664207

Can I do it?

Yes, there are ways to do this.

But you're asking the wrong question. Should you do it? No!

In general terms, I want to update the content of one ts file from another ts file. There are a bunch of functionality that is repeated way too often in my code and I am trying to automate it.

Instead of automating code-writing, you should refactor your code to avoid duplication altogether. Use the proper data structures and code structures (such as loops) so that you do not have to repeat functionality.

Upvotes: 2

Related Questions