Setup Node.js and TypeScript can be straightforward. Our daily work sometimes involves a lot of debugging and we also need to reload our server.
...
For further actions, you may consider blocking this person and/or reporting abuse
Nice, thanks for sharing.
For anyone having problems with vscode not showing the node process, do this:
nodemon --inspect:9229 src/server.ts"processId": "${command:PickProcess}"with:"port": 9229inside the launch.json file. Thats all.This is very handy to know, and I've used some of this to debug Angular Universal server side code.
In the GitHub project you linked, I notice you use
webpackfor production build. Is it necessary to usewebpackwhen using TypeScript server side?oh, thanks mate! didn't noticed it, it should be in a separated branch, not master.
it is not necessary, it is my personal approach to always bundle my server-side code, inspired by github.com/jaredpalmer/backpack
i'll update my master branch
Exactly what I was looking for... Thank you Eduardo!
Thank you for doing God's work. This is amazing.
My biggest issue has been getting nodemon working with path aliases defined in tsconfig.json
Thanks for sharing Eduardo.
Awesome, thanks
But can you please explain, how do I add support for module aliases?
thanks for your comment,
absolutely, for this setup it would be a little bit tricky, because:
let's put the production scenario above aside, and focus on "dev" only, we can do:
let's clone the repo:
and install tsconfig-paths
inside our
tsconfig.jsonwe can definebaseUrlandpaths:now we can use the alias
#domainsin any file, let's updateserver.ts:now, let's register the module alias in our
nodemon.json:now we can start the server with aliases:
and it should work as before, but with aliases!
now, for the Jest mappings, you need to keep the same mappings from
tsconfig.jsonbut in the Jest syntax/config, we need to usemoduleNameMapper. I'll add the Jest config inpackage.jsonfor this example:and now you can run your tests as before:
so far, so good.
now, for the production scenario, I do not have a good straight answer, because it requires a considerable amount of work to adapt it per project.
but thinking about the process to make it work, we could use something like module-alias
and we would need:
npm run build(e.g. typescript => node.js in dist/)package.jsonwithmodule-aliasinsidedist/tsconfig.jsoninsidedist/package.jsonbut usingmodule-aliassyntaxcd dist/ && npm installto installmodule-aliasfor productionnode --require module-alias/register entry.jsphew, what a setup! ahahah
i hope it helped! 👋
It would be nice if you could do an example with an async/await application on node and typescript.
Thank you, Eduardo!
This help me a lot.