Cross platform package json - node.js

I want to create a cross platform package json which needs to work in both mac and windows.
I have a scripts object
"scripts": {
"dev": "npm run cleanup && webpack --watch",
"build": "npm run cleanup && NODE_ENV=\"production\" webpack",
"lint": "eslint ./main/content/jcr_root/etc/designs/digital/clientlibs/src/js --fix -f table --ext .js --ext .jsx || true",
"cleanup": "rm -rf ./main/content/jcr_root/etc/designs/digital/clientlibs/dist"
},
I have tried everything but cannot set it as cross platform. Please help me with this.

Your best bet would be to rely on node modules to do the job.
For rm -rf there is a node package called rimraf.
Install the package via
$ npm i -D rimraf
And adjust your script to use it:
"scripts": {
"clean": "rimraf ./main/..."
}
Since node packages are mostly cross-OS, this should work.
You might also want to take a look at cross-env to set your NODE_ENV.
Let me know, if any additional help is required. :-)
Edit:
Since you are using webpack, there are also plugins for clean tasks as well as linting. For further information please take a look at:
clean-webpack-plugin
eslint-loader

Related

Heroku Build Not Copying React Files

I have a Node application, including an express server, set to respond to various backend requests and then to try to serve static content from a React app's build folder. It works great locally. The two different package.json files in the server and client respectively build the React app, copy its build files into the server's ./dist folder, then builds the server app and does the same, then runs the server. Everything is perfect.
However, on Heroku, the React build folder is never copied into the server's dist folder, and I get 404 errors trying to load the app. I know this worked at some point but I'm not sure what I changed that broke it and nothing is making sense to me to get it working again.
"scripts" section of the client (react) package.json:
"scripts": {
"start": "react-scripts start",
"react-build": "react-scripts build",
"build": "npm run clean && npm run react-build && npm run copy && cd server && npm run client-build",
"clean": "rimraf server/dist/",
"copy": "copyfiles build/**/* server/dist -E",
"test": "react-scripts test",
"eject": "react-scripts eject",
"prod": "cd server && npm run start"
},
and the "scripts" section of the server's package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon -i dist -i creds index.ts",
"clean": "rimraf dist/",
"copy-files": "copyfiles views/**/* assets/**/* creds/**/* dist/",
"copy-web": "copyfiles -u 1 ../build/**/* dist/ -E",
"build": "cd .. && npm run react-build && cd server && npm run clean && tsc && npm run copy-files && npm run copy-web",
"client-build": "npm i && tsc && npm run copy-files",
"start": "node dist/index.js"
},
Heroku, of course, runs npm run build from the root folder to kick off the build process, which is the client's package.json, so it runs:
npm run clean && npm run react-build && npm run copy && cd server && npm run client-build
Specifically the npm run copy doesn't seem to be doing anything. When I hit the ls through the heroku-cli, the folder is not there. I'm not getting any errors in the build.
I have been able to put a cludgey piece of code into the main server so that it checks to see if the build folder exists where it's supposed to exist before setting up the static middleware, and to go up the file tree to where they're supposed to be copied from if it doesn't, so it's working, but I don't think I should have to do this and I can't just point to the initial React build location or I'd be serving stale build's while I'm in dev locally instead of a specific dev page that links to the webpack npm run start instance that updates as I hack at it.
I understand that between the workaround in prod and just not relying on the server's static files in dev is "good enough" for me to move on, but my OCD won't let me until I understand why copyfiles works fine copying the server's extra files into dist but can't manage to copy the React app to the place it's supposed to go.
This seems like a pretty basic thing, and long run my plan here is to serve multiple independent React applications as "widgets" from different paths on the server and if I can't get the root path to behave because I'm an idiot then idk what kinds of problems I'm going to run into down the line.
TIA, lmk if any additional info is needed.
CORRECTION: I had been building an outdated version without the -E flag on the copyfiles call. Once I updated that, I did in fact get an error that no files were copied. To reiterate though, the files ARE in the build folder where they were supposed to be copied from, just not in the dist/build folder where they're supposed to go, as confirmed now by copyfiles deciding it had nothing to copy.
Is this an async issue? I thought the && suggested that the left side (the build) had to finish before the right side (the copy) would execute?

How to make Angular watch multiple libraries for changes and recompile when needed

This question is much the same as Make angular app watch for libraries changes and update itself. But, that question was never successfully answered as applies to the use of multiple libraries. I also reviewed Angular library and live reload and surveyed the answers and links from both questions.
My app is using two libraries: lib-1 and lib-2. When those files are edited, they are ignored and the app does not recompile. To see changes, I have to restart the server which really slows things down.
My expectation is that the app should be recompile when library files are edited, just like when other app-internal files are edited.
This is an Angular project that I have inherited, and the original author is no longer available. I am using Angular v10 and npm 6.14.11
The initial npm scripts are:
"start:staging": "ng serve --configuration-staging --host 0.0.0.0 --port 8080 --disableHostCheck",
"build:lib-1": "ng build lib-1 && cpx projects/lib-1/src/lib/theme.scss dist/lib-1",
"build:lib-2": "ng build lib-2 && cpx projects/lib-2/src/lib/theme.scss dist/lib-2",
"build:libs": "npm run build:lib-1 && npm run build:lib-2",
With those, I first run npm run build:libs, then npm run start:staging. As mentioned, this does not "watch" my libraries for changes.
I reviewed the suggestions and the other SO questions (above), have ensured that the npm-run-all, wait-on and rimraf libraries are now installed.
I have written these new npm scripts:
"clean": "rimraf dist",
"start-app": "wait-on dist/lib-1/fesm2015 dist/lib-2/fesm2015 && start:staging --poll 2000",
"watch:lib-1": "npm run build:lib-1 --watch",
"watch:lib-2": "npm run build:lib-2 --watch",
"watch-libs": "npm-run-all --parallel watch:lib-1 watch:lib-2",
"watch-all": "npm-run-all clean --parallel watch-libs start-app"
And, I am using the pre-existing start:staging script, as written.
I run npm run watch-all.
The script runs and proceeds to the point of building the libraries in parallel (bad idea?), and then throws error: sh: start:staging: command not found.
I removed the --parallel switches and tried again, and got the same error.
The start:staging script is indeed in the scripts object, and I cannot figure out why it's not being found.
I'm hoping to get some sage advice on correcting my syntax so that the app will compile and watch my library files along with the other files that are inside the app's src folder.
After a lot of sleuthing, I came across Nikola Kolev's Angular 6: build — watch multiple dependent libraries in one shell post.
While I don't have it down to one npm script like Nikola was able to do, I am able to do it by running two scripts (there are 7 total scripts involved), and that's good enough for now. I'll work on condensing to one when I get more time.
First, be sure to have wait-on, rimraf and npm-run-all installed. We're also using cpx; but, that's not about getting the libraries to be "watched" -- just including to be overly thorough.
Here are all the scripts:
"clean": "rimraf dist",
"watch-lib:lib-1": "ng build lib-1 --watch",
"watch-lib:lib-2": "ng build lib-2 --watch",
"watch-libs": "npm-run-all clean --parallel watch-lib:*",
"copy-styles:lib-1": "cpx projects/lib-1/src/lib/theme.scss dist/lib-1",
"copy-styles:lib-2": "cpx projects/lib-2/src/lib/theme.scss dist/lib-2",
"start-staging": "ng serve --configuration-staging --host 0.0.0.0 --port 8080 --disableHostCheck",
"watch-staging": "npm-run-all copy-styles:* start:staging"
When I want to work on the libraries and have them be "watched", I run npm run watch-libs in one terminal. When that is finished, I run npm run watch:staging in a second terminal. Then, I'm able to launch the app in a browser, and any edits to any of the code, in libraries or in the app itself are caught, and the app recompiles as desired.

'ts-node' is not recognized as an internal or external command, operable program or batch file

I'm getting error in my Vs Code terminal and command prompt that 'ts-node' is not recognized as an internal or external command, operable program or batch file. while i'm trying the start command in the terminal npm run dev and i have added my package.json file also.
{
"name": "tsnode",
"version": "1.0.0",
"description": "ts-node experiment.",
"scripts": {
"dev": "nodemon --exec 'ts-node --cache-directory .tscache' ./server.ts",
"start": "ts-node --fast ./server.ts"
},
"author": "Mugesh",
"license": "ISC",
"dependencies": {
"#types/body-parser": "^1.16.3",
"#types/chalk": "^0.4.31",
"#types/express": "^4.0.35",
"#types/node": "^7.0.18",
"body-parser": "^1.17.1",
"chalk": "^1.1.3",
"express": "^4.15.2",
"nodemon": "^1.11.0",
"ts-node": "^3.0.4",
"typescript": "^2.3.4"
}
}
You need to install ts-node as global
npm install -g ts-node
More information
https://github.com/TypeStrong/ts-node
I wouldn't recommend relying on globally installed ts-node in your own module as some of the answers here suggest.
If you do that then anyone who installs your module would need to install ts-node globally as well (just a usual npm install would not be enough) and then you will have a problem if two modules need things like ts-node globally installed but with different versions etc.
To avoid that, all your dependencies should be defined in your package.json and installed locally in node_modules.
There is a little-known command npx that is used to run binaries from modules that are installed locally in node_modules.
For example, see what happens when I install (locally) ts-node and typescript:
rsp#mn-r:~/node/test/ts-test-1$ npm i ts-node typescript
npm WARN ts-test-1#0.0.0 No description
npm WARN ts-test-1#0.0.0 No repository field.
+ ts-node#6.0.3
+ typescript#2.8.3
added 19 packages from 44 contributors in 2.157s
[+] no known vulnerabilities found [19 packages audited]
and then I try to run ts-node:
rsp#mn-r:~/node/test/ts-test-1$ ts-node -v
-bash: /Users/rsp/opt/node/bin/ts-node: No such file or directory
I can run it with npx:
127!rsp#mn-r:~/node/test/ts-test-1$ npx ts-node -v
ts-node v6.0.3
node v10.1.0
typescript v2.8.3
or I could give the path explicitly:
rsp#mn-r:~/node/test/ts-test-1$ ./node_modules/.bin/ts-node -v
ts-node v6.0.3
node v10.1.0
typescript v2.8.3
In any case, I don't need to install anything globally.
I just encountered a similar issue: on Mac OS --exec ts-node works, on Windows it doesn't.
My workaround is to create a nodemon.json like this:
{
"watch": "src/**/*.ts",
"execMap": {
"ts": "ts-node"
}
}
and change the package.json scripts section to
"scripts": {
"start": "nodemon src/index.ts"
},
The only solution that worked for me:
"start": "nodemon --exec npx ts-node ./index.ts",
I ran into the same problem and found that it works by using double quotes instead of single.
"dev": "nodemon --exec \"ts-node\" --cache-directory .tscache ./server.ts"
P.S. This is 1 year after the problem. Not sure if package versions are a factor. Will confirm if needed.
If you work under Windows you can't use single quote in the json file. That is why you have to replace all single quote symbols(') by the double quote symbols(").
But between two double quotes(") you have to use escaped double quote(").
For the current case you have to change the row in the file package.json:
"dev": "nodemon --exec 'ts-node --cache-directory .tscache' ./server.ts",
into the row:
"dev": "nodemon --exec \"ts-node --cache-directory .tscache\" ./server.ts",
Nodemon is for watching and rerunning node processes when files change. The local ts-node installed in the node_modules directory is not recognized in the scope of the --exec argument. To get around this, some people have recommended installing ts-node globally. As a user pointed out, that's not a good solution because it relies on packages external to your project and makes the ts-node in our node_modules pointless.
Edit:
With newer versions of nodemon, you can simplify this even further (note: you still need ts-node installed as a devDependency).
"start": "nodemon src/index.ts"
Previous:
To fix your solution, prefix ts-node with the npx helper, which will use your local node_module executables.
package.json, inside the scripts block:
"start": "nodemon --watch './src/**/*' -e ts --exec 'npx ts-node src/index.ts'"
An alternative approach could be to use the typescript watcher with the existing node command and the concurrently package.
"start": "concurrently \"tsc --watch\" \"node ./dist/index.js\""
Same principle. One package watches for changes (nodemon & tsc) and restarts the second process (the node/ts-node server).
Edit 11/17/2021:
I returned this post to use it as a reference for setting up a prototype build and found the nodemon approach above was no longer working, it was now throwing the error:
''npx' is not recognized as an internal or external command,
operable program or batch file.
I found a fix was to convert all single quotes to escaped double quotes.
"start": "nodemon --watch \"./src/**/*\" -e ts --exec \"npx ts-node src/index.ts\""
Guess something changed since I my original post. Hope that helps!
For me deleting node_modules and installing it again using npm i was enough.
I had the similar problem, but I have resolved by replacing
"dev": "nodemon --exec 'ts-node --cache-directory .tscache' ./server.ts",
to
"dev": "nodemon --exec ts-node --cache-directory .tscache ./server.ts",
Just remove the single quote(') and install ts-node globally
I had a similar problem while using nodemon:
I had nodemon installed globally, AND ts-node only installed locally.
Solution:
I installed ts-node globally (still keeping the local dependency).
I fixed the issue by removing single quorts around ts-node. as per below
"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts"
updated as
"dev": "nodemon --watch 'src/**/*.ts' --exec ts-node src/index.ts"
please note. my environment is windows 10 and npm version6.14.4
Like suggested in some answers, you should install ts-node locally and not globally. npx makes it easy to use CLI tools and other executables hosted on the registry as explained here. Hence, can be used to run ts-node on your terminal and even scripts from your package.json file. For example;
Take this to be my package.json file
{
...
"scripts": {
"start": "npx nodemon path/to/file"
}
}
Now running npm run start would not give any more issues.
You can try the following command
"dev": "nodemon --watch './**/*.ts' --exec \"ts-node\" src/index.ts"
This worked for me .
If your ts-node isn't working, as an alternative you can do the following:
1) Install nodemon locally --> npm i nodemon
2) In your package.json 'scripts' add the following:
"scripts": {
"start": "nodemon index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
3) Now run npm start (this will automatically run node for you, but this WILL NOT COMPILE TS )
4) Open a new tab in the terminal/command line, cd the folder your working in and run tsc index.tsc --watch
This will compile your typescript. The only downside is you will just have to have both tabs open, one for running node automatically and the other for compiling automatically, but this works.
I was having the same issue on windows. I found the solution for my issue was resolved when I corrected some misplaced '
Originally:
"scripts": {
"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts",
"build": "tsc",
"start": "node dist/index.js"
}
Fixed:
"scripts": {
"dev": "nodemon --watch 'src/**/*.ts' --exec \"ts-node\" src/index.ts",
"build": "tsc",
"start": "node dist/index.js"
}
The difference in case it isn't clear is that I no longer wrap ts-node in '
* EDIT *
I changed this based on the answer from #RoutesMaps.com above. This solved my problem as well as removing the ' but #RoutesMaps.com actually explains the issue resolution
I ran this command after npm install ts-node.
This fixed my problem:
npm install -D tslib #types/node
yarn add -D ts-node
"scripts": {
"start": "ts-node src/index.ts"
}
'yarn start' now works
Found the answer.
Without installing ts-node globally, just create inside your project nodemon.json file and put it there :
{
"execMap": {
"ts": "node --loader ts-node/esm"
}
}
So now, you can keep type:"module" in your package.json and module:"ESNEXT(or smth that supports ES Modules)" in your tsconfig.json. However, you are going to get constant warning from nodemon that it's, I mean loader type, experimental feature but it's not critical.
In your package.json, in dev command for example just run nodemon path/filename.ts
If you are using a mac these are the steps I came up with in order to fix this in the terminal.
Install globaly and use the returned file path with the symlink ‘ts-node’ and move this file into /usr/local/bin
Install locally without saving to package.json
copy folder in /node_modules into /usr/local/lib/node_modules/
Make sure the file is executable by opening /ts-node/dist and using the command chmod +x bin.js
run npm i in ts-node folder
Make sure that dist folder still exsists, if not copy it back over.
Test running ts-node in terminal, if it does not work it will return an error of which module needs to be moved over to ../
After ts-node runs be sure to delete the folder /usr/local/lib/node_modules/ts-node/node_modules
I was having the same issue. I found the solution for my issue was resolved when i do simply run this command first "npm run build" and than try it nodemon and also add in package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"dev": "ts-node ./lib/server.ts",
"start": "nodemon ./dist/server.js",
"prod": "npm run build && npm run start"}
If you are using code-runner in vs-code then edit setting.json file
"typescript": "tsc $fileName && node $fileNameWithoutExt.js "
Write the the script like this inside your package.json file
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rimraf ./build && tsc",
"start": "node build/index.js",
"tsc": "tsc",
"watch-node": "nodemon build/index.js",
"postinstall": "npm run tsc"
},
Then, npm run build
and finally npm run start
I encountered the same error when trying to run nodemon from a Git Bash but it seems to be working just fine when running nodemon from PowerShell. So, you should consider giving some other terminals a chance.
Me helped this command
npm i -D typescript
More specifically written there https://nodejs.dev/learn/nodejs-with-typescript
Please use TSC --init, instead of TS --init
this error can occur if you have one version of ts-node installed in your project and another version globally.
To solve the problem - install the same version of the package
Just had this same problem and came up with a hybrid solution, using npx to execute but via nodemon config (rather than package.json).
nodemon.json...
{
"watch": ["src"],
"ext": "ts",
"exec": "npx ts-node ./src/server.ts"
}
Actually if you install nodemon as globally then install ts-node also globally. If you install nodemon as -D (dev dependency) then install ts-node as dev dependency. It will work.
A bit late to the party, but my issue was that I had set the NODE_ENV=Production environment variable on my CI. When NODE_ENV is set the dev dependencies(where the ts-node was listed) won't be installed.
Removing NODE_ENV fixed the issue.
I removed it from dev dependencies and added it to dependencies. That solved the problem for my case.

How do I deploy my Typescript Node.js app to Heroku?

When testing locally I was previously running:
"build-live": "nodemon --exec ./node_modules/.bin/ts-node -r dotenv/config -- ./index.ts"
I then figured my Procfile should be something like:
web: ./node_modules/.bin/ts-node -- ./index.ts
But it says module 'typescript' not found, even when it is in package.json. I read in a few places that ts-node is not the way to go to deploy to Heroku, so I am not sure what to do.
UPDATE: I think I am supposed to compile it, so I tried:
web: ./node_modules/.bin/tsc --module commonjs --allowJs --outDir build/ --sourceMap --target es6 index.ts && node build/index.js
This succeeds, however when actually running it, a bunch of the libs I'm using get "Cannot find module '...'".
Alternatively you can have the TypeScript compile as a postinstall hook and run node build/index.js as the only Procfile command:
Your package.json should contain a postinstall hint that gets executed after npm install and before the node process launches:
"scripts": {
"start": "node build/index.js",
"build": "tsc",
"postinstall": "npm run build"
}
You can then leave your Procfile as is:
web: npm start
This 'build on deploy' approach is documented by Heroku here.
The command you've given Heroku is to launch the web "process" by compiling index.ts and dependencies and starting node at index.js. Depending on how things are timed, index.js might or might not exist at the time node starts.
You need to already have your sources compiled by the time you want to start your app. For example, web should just be web: node index.js or similar.
Each build process is different, so you need to figure that out for your own setup. But, suppose you have a classical setup where you push to git and then Heroku picks up that change and updates the app with the new slug. You could just compile things locally and include index.js and any other build output in the repository, for it to be available in the slug for Heroku to use.
A better approach is to use a build server which has an integration with Heroku. After you do the build there, configure it to send the build results to Heroku. Travis has a straighforward setup like this. This way you don't need to include build outputs in your repository, which is considered an anti-pattern.
On a sidenode, try using a tsconfig.json to keep the tsc configuration. It will save you from having to write such long command lines all over the place.
Fabian said that we could do something like:
"scripts": {
"start": "node build/index.js",
"build": "tsc",
"postinstall": "npm run build"
}
As of me writing this, I tested this and can state: postinstall is not required since build script is ran by Heroku. If you want to do it without build script, then you can use heroku-postbuild which will run after dependencies are installed there you run tsc to compile.
My problem was about missing Typescript npm modules. The Typescript compiler tsc was not found when deployed the app to Heroku.
The Heroku deploy process (rightly) does not install development dependencies, in my case the Typescript module was part of devDependencies and thus the tsc command was not running on the Heroku platform.
Solution 1
Add typescript to dependencies: npm i typescript -s
Solution 2
Open Heroku console:
Select console type:
Run the command npm i typescript && npm run tsc
Install typescript as a dev dependency (cf. https://www.typescriptlang.org/download). Once built, your app does not need typescript anymore!
npm install -D typescript
Then in your package.json:
{
"main": "index.js", // <- file will be generated at build time with `tsc`
"scripts": {
"build": "tsc",
"start": "node ."
"start:dev": "ts-node index.ts" // idem, install ts-node as a dev dependency
}
}
The key point here is "build": "tsc".
Why?
Heroku does install all dependencies during build and remove the dev dependencies before the app is deployed (source here).
Node.js deployments will automatically execute an app’s build script during build (since March 11. 2019 source here)
In package.json
"scripts": {
"tsc": "./node_modules/typescript/bin/tsc",
"postinstall": "npm run tsc"
},
Works for me for Heroku deployment.
Installing typescript npm install -D typescript and writing tsc in the build script "build": "tsc", does not work for me. Also, try to run npm i typescript && npm run tsc in the Heroku console which also does not work.
In my case, I remove some dependencies from "devDependencies" to "dependencies", so it goes like this:
"dependencies": {
// The other dependencies goes here, I don't touch them.
// But all TS dependencies I remove to here.
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.2.3",
"ts-loader": "^8.0.18"
},

How do I execute typescript watch and running server at the same time?

I was developing my project in nodejs. I found if I need to code and test api, I will run two console, one is to execute typescript watch, another is to execute server.
I think it's so troublesome. I find other developers on github have written scripts in package.json. It's easy to call any commands. It attracts how to write the scripts and simply my development workflow.
In short, the comand of typescript watch is tsc -w and the comand of running server is node app.js. My idea is merge the commands as tsc -w & node app.js but I can't work the two commands at the same time. How do I do? Thanks.
My idea is merge the commands as tsc -w & node app.js but I can't work the two commands at the same time. How do I do
You have a few options. Simplest is to use ts-node-dev : https://github.com/whitecolor/ts-node-dev
Option 1
Step 1
install concurrently, use npm, pnpm or yarn
pnpm i concurrently -D
Step 2
create a script with this command
"scripts": {
"run": "tsc && concurrently \"tsc -w\" \"nodemon dist/app.js\"",
}
Option 2
without install anything (mac or Linux)
"scripts": {
"run": "tsc -w & nodemon dist/app.js",
}
run tsc first so that your directory has something at the time of running node
And with that you will have running your Typescript application 🚀
Another option can be to use nodemon:
tsc -w & nodemon app.js
Since Typescript 3.4 the compilation is faster because you can use the incremental compiler option and they keep improving (including interesting changes for large projects in 3.8).
Update:
I also moved to use concurrently as HerberthObregon says in his answer
TLDR, If you like nodemon this is a straight forward way to get file watch, compilation and execution:
nodemon --ext ts --exec 'tsc && node dist/index.js'
Optionally replace tsc with babel for faster compilation.
Here is a more complete example, in package.json (with source maps):
"scripts": {
"develop": "nodemon --ext ts --exec 'yarn build --incremental && yarn serve'",
"build": "tsc",
"serve": "node --require source-map-support/register dist/index.js",
...
},
Install source-map-support as a dependency if you want, ahem... source map support! Otherwise, remove --require source-map-support/register from the serve script above.
tsconfig.json
{
"compilerOptions": {
...
"sourceMap": true,
"outDir": "dist",
}
}
Building on herberthObregon's answer
Step 1: Install packages
npm install concurrently typescript nodemon --save-dev
Step 2: Create these scripts in package.json
"scripts": {
"build": "tsc",
"build:watch": "tsc -w",
"dev": "npm run build && concurrently \"npm run build:watch\" \"npm run serve:watch\"",
"serve": "node dist/index.js",
"serve:watch": "nodemon dist/index.js"
},
build runs a standard typescript build
build:watch runs typescript build in watch mode
serve serves up your node project (assuming your tsconfig outputs to dest/index/js)
serve:watch uses nodemon to restart the node server whenever the js output changes
dev puts them all together
Just going to throw my hat in here, here's a solution using ts-node-dev and concurrently, similar to the one provided by #HerberthObregon but using ts-node-dev instead of nodemon:
"scripts": {
"start": "npm run build && concurrently \"npm run build:watch\" \"npm run dev\"",
"dev": "tsnd --respawn src/main.ts",
"build": "tsc -p tsconfig.release.json",
"build:watch": "tsc -w -p tsconfig.release.json"
}
Bonus: If you need help with your figuring out tscand your tsconfig.json, I use the sensible defaults from this node typescript starter.
Here's a solution that works for me
1. Install ts-node and nodemon as dev dependencies
2. Create a script : "dev" : "nodemon app.ts"

Resources