TypeScript and NodeJS: The Proper Setup!

  Рет қаралды 47,550

Josh tried coding

Josh tried coding

Күн бұрын

Let's set up TypeScript with NodeJS properly! To do that, we'll take a look at what precompiling is, to then look at how TypeScript gets compiled to Javascript in action. Really interesting stuff. And after understanding that, we can take a look at an npm-package that does that stuff under the hood for us.
Thanks for watching, I hope you found this as interesting as I did! Cheers

Пікірлер: 29
@ballonura
@ballonura Жыл бұрын
Why dir called "server" and no "src"? (naming best practice)
@kevinolds9614
@kevinolds9614 Жыл бұрын
I was going to ask this. Still, great video.
@piiaall
@piiaall Жыл бұрын
Your explanation is very clear
@greggsworld4453
@greggsworld4453 Жыл бұрын
This was great! Thank you so much. It would be great if you added server restart on code changes to avoid having to start and stop - like nodemon.
@Theforrestfire217
@Theforrestfire217 10 ай бұрын
Hi greggsworld. You should be able to do that with something like this: "dev": "tsc-watch --onSuccess \"yarn start\"", "start": "node dist/app.js" using tsc-watch will keep an eye out for code changes
@kurtking4662
@kurtking4662 Жыл бұрын
Enjoyed watching your video!
@LorenzoJimenez
@LorenzoJimenez 10 ай бұрын
You actually forgot to install typescript as a full complete explanation. Thanks for the video
@phongnguyen.5322
@phongnguyen.5322 8 ай бұрын
Many help, thank you
@piotrjasiulewicz408
@piotrjasiulewicz408 6 ай бұрын
god tier level video
@ilearncode7365
@ilearncode7365 Жыл бұрын
how does tsc still work after you moved it into a folder? That doesnt make sense.
@user-qn8if8bb7x
@user-qn8if8bb7x 10 ай бұрын
Amazing!
@patelronak153
@patelronak153 16 күн бұрын
Great🚀🚀❤❤
@reihane2325
@reihane2325 9 ай бұрын
thanks , so helpful
@muhammadbilalmalik7292
@muhammadbilalmalik7292 9 ай бұрын
how tsc command is automatically executing server/index.ts ?
@NoName-qu3tw
@NoName-qu3tw 11 ай бұрын
Great! Thank you!
@ponchobob
@ponchobob Жыл бұрын
maybe for some others here a simple or stupid question, but is nodejs used in big companies for their backend? or is this just some sort of "hobby backend library" ?
@0xSLN
@0xSLN Жыл бұрын
Probably the biggest in the industry. What else compares in adoption? Low level systems use a lot of C but companies want many good devs and good libs. So community size is a proxy for that. Js has biggest community, node is server js.
@tropicalreptile6288
@tropicalreptile6288 Жыл бұрын
yeah LinkedIn and nasa are just hobby backend thing
@redeemr
@redeemr 9 ай бұрын
@@0xSLN javascript is so big because it is basically required on the front-end. On the back-end, there are tons of options that are faster and more mature than node.js. I doubt it's the most popular.
@0xSLN
@0xSLN 9 ай бұрын
@@redeemr Its based on number of projects on github. But popular doesn't equal best, lots of langs that are better at specific things.
@samking618
@samking618 3 ай бұрын
Express has around 22M+ weekly downloads as of today
@okage_
@okage_ Жыл бұрын
do you have a link to your github or is it private
@onequy6648
@onequy6648 Жыл бұрын
gooodddd, thank youuuu
@ramiworkstation
@ramiworkstation 2 ай бұрын
Sweet like Sugar 🍬🍬
@naumanshigri
@naumanshigri 7 ай бұрын
belot han ongs na sokor yaa
@scorcism.
@scorcism. Жыл бұрын
subscribed
@WarframeCrunch
@WarframeCrunch Жыл бұрын
I don't know why I'm getting this error :/ \middleware\errorHandler.ts:45 export default errorHandler; ^^^^^^ SyntaxError: Unexpected token 'export' My server.ts file: const express = require("express"); const errorHandler = require("./../middleware/errorHandler"); const dotenv = require("dotenv").config(); const app = express(); const port = process.env.PORT || 5000; app.use(express.json()); app.use("/api/contacts", require("./../routes/contactRoutes")); app.use(errorHandler); app.listen(port, () => { console.log(`Server running on port ${port}`); }) and errorHandler.ts file: import {Request, Response} from 'express'; type typeErrorHandler = { err: {message: string, stack: string[]}, req: Request, res: Response, next: string, } const errorHandler = ({err,req,res,next} : typeErrorHandler) =>{ const statusCode = res.statusCode ? res.statusCode : 500; switch (statusCode) { case 400: res.json({ title: "Validation Failed", message: err.message, stack: err.stack, }) break; case 401: res.json({ title: "Un authorized", message: err.message, stack: err.stack, }) break; case 403: res.json({ title: "Forbidden", message: err.message, stack: err.stack, }) break; case 404: res.json({ title: "Not found", message: err.message, stack: err.stack, }) break; case 500: res.json({ title: "Server Error", message: err.message, stack: err.stack, }) break; default: console.log('No error, all good.'); break; } } export default errorHandler;
@redeemr
@redeemr 9 ай бұрын
you're mixing require and esm syntax. You should look into what adding "type": "module" does or what using the .cjs and .mjs file extensions do. I'm sure you've already solved the problem but I'm just leaving this here for future reference.
How To Use TypeScript With Express & Node
17:05
Colt Steele
Рет қаралды 70 М.
How Did I Not Know This TypeScript Trick Earlier??!
9:11
Josh tried coding
Рет қаралды 211 М.
How Strong is Tin Foil? 💪
00:26
Preston
Рет қаралды 47 МЛН
Fetching Data Doesn't Get Better Than This
6:58
Josh tried coding
Рет қаралды 115 М.
Typescript API in NodeJS / Express in Depth [Part 1]
38:10
The Nerdy Canuck
Рет қаралды 8 М.
Authenticate your Next.js app in 100 seconds with Clerk
2:37
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 645 М.
How to setup Nodejs Express with Typescript
28:20
Mafia Codes
Рет қаралды 17 М.
Updates Like These Make Tailwind So Fun
8:00
Josh tried coding
Рет қаралды 73 М.
The Better Way to Load Images
8:46
Josh tried coding
Рет қаралды 46 М.
Express JS with TypeScript - Setup, Examples, Testing
1:20:13
Anson the Developer
Рет қаралды 29 М.