Комментарии:
Why dir called "server" and no "src"? (naming best practice)
Ответитьdo you have a link to your github or is it private
ОтветитьYour explanation is very clear
Ответить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" ?
Ответить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;
subscribed
Ответить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.
Ответитьhow does tsc still work after you moved it into a folder? That doesnt make sense.
ОтветитьEnjoyed watching your video!
Ответитьtsx (package, not react's tsx), is better than ts-node
it just always works
even lets you execute .ts files directly with this hashbang `#!/usr/bin/env tsx`
gooodddd, thank youuuu
ОтветитьGreat! Thank you!
ОтветитьYou actually forgot to install typescript as a full complete explanation. Thanks for the video
ОтветитьAmazing!
Ответитьthanks , so helpful
Ответитьhow tsc command is automatically executing server/index.ts ?
ОтветитьMany help, thank you
Ответитьbelot han ongs na sokor yaa
Ответитьgod tier level video
ОтветитьSweet like Sugar 🍬🍬
ОтветитьGreat🚀🚀❤❤
Ответитьthanku brother for this valuable information
ОтветитьGreat video, I am having a problem, I can’t use ts-node with esm, I keep getting an error
Ответитьthanks man, step by step explan.. really help
Ответитьdon't use ts-node use vite-node and save your time!
Ответитьwhere can I find that wallpaper
ОтветитьSuch a quick and clear tutorial. Wonderful job!
Ответитьit's not good tutorial you why you don't show how to use modules etc. ?
Ответить