TypeScript and NodeJS: The Proper Setup!

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 พ.ย. 2024

ความคิดเห็น • 35

  • @Vegasguy79
    @Vegasguy79 21 วันที่ผ่านมา

    Such a quick and clear tutorial. Wonderful job!

  • @piiaall
    @piiaall ปีที่แล้ว +2

    Your explanation is very clear

  • @Imam_Faheem_khan
    @Imam_Faheem_khan หลายเดือนก่อน

    thanks man, step by step explan.. really help

  • @greggsworld4453
    @greggsworld4453 ปีที่แล้ว +1

    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 ปีที่แล้ว +5

      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

  • @LorenzoJimenez
    @LorenzoJimenez ปีที่แล้ว

    You actually forgot to install typescript as a full complete explanation. Thanks for the video

  • @TechAlly-07
    @TechAlly-07 2 หลายเดือนก่อน

    thanku brother for this valuable information

  • @kurtking4662
    @kurtking4662 ปีที่แล้ว

    Enjoyed watching your video!

  • @ballonura
    @ballonura 2 ปีที่แล้ว +12

    Why dir called "server" and no "src"? (naming best practice)

    • @kevinolds9614
      @kevinolds9614 ปีที่แล้ว +2

      I was going to ask this. Still, great video.

  • @phongnguyen.5322
    @phongnguyen.5322 11 หลายเดือนก่อน

    Many help, thank you

  • @kennedydre8074
    @kennedydre8074 2 หลายเดือนก่อน

    Great video, I am having a problem, I can’t use ts-node with esm, I keep getting an error

  • @MdSalman-w8g
    @MdSalman-w8g หลายเดือนก่อน

    where can I find that wallpaper

  • @reihane2325
    @reihane2325 11 หลายเดือนก่อน

    thanks , so helpful

  • @PavanKumar-g7v1q
    @PavanKumar-g7v1q ปีที่แล้ว

    Amazing!

  • @NoName-qu3tw
    @NoName-qu3tw ปีที่แล้ว

    Great! Thank you!

  • @muhammadbilalmalik7292
    @muhammadbilalmalik7292 11 หลายเดือนก่อน

    how tsc command is automatically executing server/index.ts ?

  • @piotrjasiulewicz408
    @piotrjasiulewicz408 8 หลายเดือนก่อน

    god tier level video

  • @ilearncode7365
    @ilearncode7365 ปีที่แล้ว

    how does tsc still work after you moved it into a folder? That doesnt make sense.

  • @one_quy
    @one_quy ปีที่แล้ว

    gooodddd, thank youuuu

  • @patelronak153
    @patelronak153 2 หลายเดือนก่อน

    Great🚀🚀❤❤

  • @okage_
    @okage_ 2 ปีที่แล้ว

    do you have a link to your github or is it private

  • @scorcism.
    @scorcism. ปีที่แล้ว

    subscribed

  • @naumanshigri
    @naumanshigri 10 หลายเดือนก่อน

    belot han ongs na sokor yaa

  • @ramiworkstation
    @ramiworkstation 5 หลายเดือนก่อน

    Sweet like Sugar 🍬🍬

  • @statuschannel8572
    @statuschannel8572 หลายเดือนก่อน

    don't use ts-node use vite-node and save your time!

  • @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 ปีที่แล้ว +2

      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 ปีที่แล้ว

      @@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 ปีที่แล้ว

      @@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 6 หลายเดือนก่อน

      Express has around 22M+ weekly downloads as of today

  • @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 ปีที่แล้ว +1

      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.