Hey guys! Thanks for watching. Just a small FYI: I missed an important part of logging, in the current example, the logging on the server will only log the req before the response is returned, so I fixed it in the repo to listen for the response to end. Please take a look at: github.com/joeythelantern/Typescript-Quickstart-Projects/blob/main/typescript-mysql-quickstart/source/server.ts
@anselmleo41463 жыл бұрын
Nice.. I was wondering why you didn't go with Winston or other loggers out there. Is this the best approach with Typescript?
@TheNerdyCanuck3 жыл бұрын
@@anselmleo4146 Nope, just an easy way to do it on your own.
@TheNerdyCanuck3 жыл бұрын
Hola, también estoy usando un traductor. Muchas gracias, estoy feliz de que te gusten mis videos.
@ProximityGM3 жыл бұрын
Why do you want the request to log after the response is returned? I don't see how this is a mistake. Can you please explain?
@brennonwilliams91812 жыл бұрын
Seriously, one of the best tutorial videos I have seen in a very long time. Your delivery of the content is perfect because you're not showing things that make you look smart and nobody needs or the context is a distraction - you're showing exactly the content needed, with a great cadence, enough detail without getting stuck in the weeds, and showing a logical path to constructing the solution. Well done sir.
@janlestermallari3 жыл бұрын
This is so far the *EASIEST* and *STRAIGHTFORWARD* TS setup I've ever watched. Thanks for this short tutorial.
@TheNerdyCanuck3 жыл бұрын
No problem. I goal is always to be thorough and as accurate as possible.
@johnnydriesen75753 жыл бұрын
This channel is far underrated. Thanks for this great vid, @Canuck.
@TheNerdyCanuck3 жыл бұрын
No problem! It's not even that it's underrated, I've just been away from KZbin for a long time and couldnt concentrate on it before. Hopefully my releasing of a video once or twice a week from here on out brings people back :)
@IkraamDev3 жыл бұрын
First time I’ve seen someone do logging like this in a tutorial.
@TheNerdyCanuck3 жыл бұрын
Is that a good thing?
@IkraamDev3 жыл бұрын
@@TheNerdyCanuck Yeah, it's something different.
@NikhilAdiga3 жыл бұрын
Yes! Usually people use libraries like Morgan. This is something different.
@PovilasCiplis3 жыл бұрын
very efficient, no bs, straight to the point. loving this. see you at 100k subscribers very soon.
@TheNerdyCanuck2 жыл бұрын
I hope so
@derik46223 жыл бұрын
Had such a fun time with this! Really great content!
@walid71893 жыл бұрын
This is one of the best tutorials I have ever come across. Thanks.
@TheNerdyCanuck3 жыл бұрын
No problem! Like and share my friend :)
@dahutt3 жыл бұрын
Thank you for this! I've been beating my head at the wall for the past week trying to learn how to set something like this up this and this finally did it.
@TheNerdyCanuck3 жыл бұрын
I got u!
@sivak71833 жыл бұрын
This is the best explanation I have ever found, Keep going well done.
@AnsiString2 жыл бұрын
Just awesome! That was exactly that, I was looking for. Thousand thanks to you. Greetings from Germany.
@mishasawangwan66523 жыл бұрын
first: thank you for taking the time to share your knowledge. it’s clear from the comments this video is helpful for many just getting started. and that’s great but .. the video title is misleading: there’s basically no usage of typescript in this video. yes there are maybe 2 examples where you use type hints in some function signatures but aside from that, this is just vanilla javascript.
@TheNerdyCanuck3 жыл бұрын
That's because for a basic example like this, there isn't much difference
@Jason-yr6fy2 жыл бұрын
Do you have adjusted or know a template that uses more typescript? Would be interesting to see :)
@ulana11893 жыл бұрын
Clear, nice and informative. You should make proper video tutorial with React+Redux, Node+Express+Mongo with typescript. I am sure it would be one of the best tuts. Looking forward 😎
@TheNerdyCanuck3 жыл бұрын
I'm actually doing on with mongo right now, should be out within a few days 🤓
@ulana11893 жыл бұрын
@@TheNerdyCanuck cool👍👍👍
@TheNerdyCanuck3 жыл бұрын
@@ulana1189 It's up, let me know what you think!
@djmous53672 жыл бұрын
Well organized and to the point. How can I have VSCode stop at breakpoints? extensions needed? launch.json configuration? please specify or point me to an actual example. Thank you.
@phamvanhan70373 жыл бұрын
The best video I could found! Thank you.
@madhand14722 жыл бұрын
great video! could you explain soft delete with node js
@RushabhWadkar3 жыл бұрын
This was so great. Perfect! Exactly what I needed.
@TheNerdyCanuck3 жыл бұрын
:)
@juanchox09293 жыл бұрын
What an excellent explanation!! Thanks for sharing your knowledge, I'll put it on practice right now
@supa10093 жыл бұрын
Bro you are a legend, like really thank you for your help!
@KuRoiBatusai3 жыл бұрын
Hello, looking for a node + typescript tutorial, I found your video, by the way TOO good, I am a Spanish language, so if something is a little strange it is because of the translator ajja, this time I wanted to write more than necessary, because I see that you Programming logic is similar to mine, that's why I loved your video a lot and I always wondered can I do this, how is it done, and you just leave your log for future use for monitoring (DevOps), etc. Then I see the github and you have the same thing in mongoose, I learned more things by watching your video and you earned a subscriber, continue like this, good material and now I'm watching all the videos, thanks for your hard work. By the will it was that he used a translator. Greetings from Chile
@KrisFoster13 жыл бұрын
Great video, thank you! Any reason why you don't use a popular middleware logging package like morgan?
@TheNerdyCanuck3 жыл бұрын
You can totally use any logger you want! I prefer to do simple things myself to not bloat my libraries, but a logging library wouldn't really bloat anything. It's just personal preference on small projects :)
@tamarperetz96413 жыл бұрын
Thank you so much! really informative and helpful
@SuperZartok3 жыл бұрын
Thanks a lot for this tutorial
@leonardo.cardoso Жыл бұрын
really good tutorial!
2 жыл бұрын
do you have a continuation of this tutorial on how to store stuff on mongo or something?
@TheNerdyCanuck2 жыл бұрын
Yes, if you go to my recent uploads, I have a video similar to this about mongo.
2 жыл бұрын
@@TheNerdyCanuck Thanks
@giovannipizzato68882 жыл бұрын
Dude you are awesome, thanks!
@TheNerdyCanuck2 жыл бұрын
no you are!
@ShinYo6273 жыл бұрын
Can you elaborate the purpose of logging functions from /source/logging bit more please? I get that they are reusable functions that are supposedly used for loggings when having different situations like logging infos inside error handlers or just infos on every request.... (hope I'm getting right so far here) . Then, how can you use the debug function from logging.ts in future? I'm just asking because it's just fascinating to find some different working method/pattern than I'm used to.
@TheNerdyCanuck3 жыл бұрын
I use logging like this as it's lightweight and I'm just interesting in console logging, however you could expand those functions for sure
@SpencerDavis20003 жыл бұрын
great tutorial thanks
@TheNerdyCanuck3 жыл бұрын
No problem!
@isidme3 жыл бұрын
Awesome tutorial, thanks.
@jotube62043 жыл бұрын
Hey Nerdy Canuck, your tutorials a awesome. How can I contact you for further payed support? Greetings Jo
@TheNerdyCanuck3 жыл бұрын
How can I help you? What kind of support do you need.
@aleksandarhristov29183 жыл бұрын
Great tutorial. Much appreciated!
@TheNerdyCanuck3 жыл бұрын
No problemo!
@manthanpatel7793 жыл бұрын
Love this Tutorial
@prakharkapoor25723 жыл бұрын
how i deploy build folder to heroku or somewhere else?pls make a video on it
@TheNerdyCanuck2 жыл бұрын
I have made a video for you
@rushabhmehta94583 жыл бұрын
Amazing video, thanks - I'll admit I did a double take at const router = express(); -> much more used to people doing app = express();
@TheNerdyCanuck3 жыл бұрын
Yeah me too! Even when I name it router sometimes I do the same thing haha!
@AnkurJhavery2 жыл бұрын
My node installation never gives a summary after installing packages like shown in the video: body-parser@1.19.0 + express@4.17.1; how do I get this?
@TheNerdyCanuck2 жыл бұрын
Do you want specific versions or more console output?
@Nico-zl8cf3 жыл бұрын
great tutorial, thank you!
@TheNerdyCanuck3 жыл бұрын
no problem :) .. Any other tutorials you would like to see?
@ashiqsultanmohamed97653 жыл бұрын
Can I know why you are not using a pre build npm package for logging? like Morgan
@TheNerdyCanuck3 жыл бұрын
Just personal preference, you can use any logging you want
Thank you! Let me know a topic you'd like me to cover in the future!
@IkraamDev3 жыл бұрын
Would you keep the logging in production?
@TheNerdyCanuck3 жыл бұрын
In production, I would log to a file using a log library that has some sort of log rotation.
@spottedZebra072 жыл бұрын
Hi, what is the resolution of your monitor? Video looks crisp on mine at 1440p
@TheNerdyCanuck2 жыл бұрын
I do my videos in 2K (1440p)
@d-one-and-only3 жыл бұрын
Just wondering why would you split up the controller and the rouites into two separate files? Would it have not been a bit more unified if the 'controller' would include the router and export the router?
@TheNerdyCanuck3 жыл бұрын
When API's get large it's better to have things separated as when you scale up it can get chaotic in the code. That's my personal opinion anyways, I like to compartmentalize things.
@usmanmughal59163 жыл бұрын
Hey use typegoose with typegraphql
@mehmetaltinsoy5254 жыл бұрын
Nice video.Thanks.
@TheNerdyCanuck4 жыл бұрын
No problem! Please like and share :)
@СаидТашманов3 жыл бұрын
Спасибо!
@TheNamesJT3 жыл бұрын
This timestamp section is out of my scope of understanding what hes doing 10:50 do you have a video teaching headers, responce and request? like the rules of the api commented section would have never of known to do that. Even tutorials teaching restapi don't include the header rules. Update: Alright 18:36 can't seem to run server.ts it says my logging.info isn't a function on line 50 also added a .env file and added those 2 variables in it SERVER_PORT - SERVER_HOSTNAME and then deleted the config.ts script and just added process.env.SERVER_HOSTNAME and the other one to the functions that was using the config because for some reason was getting undefined for my env's so that fixed those error but now my logging functions aren't being recognized as functions line 50 even though everything is spelt right and did exactly what you did at 18:35
@TheNerdyCanuck3 жыл бұрын
I find that if I'm having issues with ENV vars I just hard code them first in the config (without using dotenv) to make sure they are working properly first. Once I get the API running, then I would go back and try and fix em.
@TheCstriker3 жыл бұрын
Also, maybe I'm wrong (as I'm not a backend developer but trying to learn), but shouldn't next be called on the sampleHealthCheck controller function?
@TheNerdyCanuck3 жыл бұрын
The reason we don't call next is because that function is the last stop before we return a response to the user. Once you return a response, the next function has nothing to pass the request to.
@TheCstriker3 жыл бұрын
@@TheNerdyCanuck so that means only middleware functions should call next in order to cascade into each other right? And if that’s true, can’t we just don’t declare that parameter and live with req and res only?
@TheNerdyCanuck3 жыл бұрын
@@TheCstriker Correct. Next is used if you need to continue with the request. Technically you could not declare 'next' on the function, but I like to put them in because I think it's good coding practice to always know the parameters available to you even if you are not using them. :)
@newstuff06293 жыл бұрын
design code so great men, thanks!
@johnkarippery99192 жыл бұрын
why i get this error after npm run build > api@1.0.0 build > rm -rf build/ && prettier --write source/ && tsc 'rm' is not recognized as an internal or external command, operable program or batch file.
@TheNerdyCanuck2 жыл бұрын
Thats because you aren't running it on a compatable terminal. rm -rf is meant for bash. If you are using powershell or something like that, you have to change it to that terminals command
@aram56422 жыл бұрын
I find coding to be not as much challenge as getting eslint to work in vscode the way I want. What a nightmare!
@josuequinteros37894 жыл бұрын
thanks, so time booster
@TheNerdyCanuck3 жыл бұрын
No problem! If you have any requests let me know :)
@spaghettispaghetto4 жыл бұрын
great video
@TheNerdyCanuck4 жыл бұрын
Thanks. Any specific topic you want covered in the future?
@hiepnguyen17743 жыл бұрын
amazing, good job (y)
@TheNerdyCanuck3 жыл бұрын
No problem! If you have any requests let me know :)
@tauseefanwardo2 жыл бұрын
why do your req, res and next not asking for type, as we are developing in typescript in the server.ts file?
@TheNerdyCanuck2 жыл бұрын
When using a router, express automatically injects them / knows the types. When you define it separately, then you must define them like in the controller
@tauseefanwardo2 жыл бұрын
@@TheNerdyCanuck Good Stuff! Thanks!
@nect32763 жыл бұрын
can someone tell me why i get always an empty json back
@TheNerdyCanuck3 жыл бұрын
What does your controller function look like?
@touhidulshawan963 жыл бұрын
How to logout user from this implementation?
@TheNerdyCanuck2 жыл бұрын
No need for this implementation
@zainjahangir2962 жыл бұрын
hi im facing an error when i try to run the server Unknown file extension ".ts"
@TheNerdyCanuck2 жыл бұрын
What command are you using
@tristheflash69283 жыл бұрын
this is the frist i try with node js and express js , i feel config really complex with me :(
@TheNerdyCanuck2 жыл бұрын
What can I do to help?
@roshanchauhan20573 жыл бұрын
Getting error while build the app "Error: Cannot find module 'express'
@TheNerdyCanuck3 жыл бұрын
What folder are you trying to run from? Did you import at the top?
@roshanchauhan20573 жыл бұрын
@@TheNerdyCanuck I run this folder and command nodemon source/server.ts
@TheNerdyCanuck3 жыл бұрын
@@roshanchauhan2057 perhaps you forgot the type definitions?
@sourabhvaishnav82353 жыл бұрын
app.use(cors()); could have shorten the video by a minute.
@TheNerdyCanuck3 жыл бұрын
Probably
@siphenathindabazonke88953 жыл бұрын
why is it complaining about import statement outside a module and pointing to the HTTP import?
@TheNerdyCanuck2 жыл бұрын
Where is the error in your code (paste it here)
@dharmarajr243 жыл бұрын
Ts-node 😭
@TheNerdyCanuck3 жыл бұрын
Yeah I've had my issues with it as well haha
@dharmarajr243 жыл бұрын
@@TheNerdyCanuck Finally managed to run my node server. The issue was 'tsc src/index.ts' wasn't running.. but only 'tsc' did. Maybe specifying filename ignores tsconfig
@TheNerdyCanuck3 жыл бұрын
@@dharmarajr24 you mean in your package.json file? Yeah if index is in there it'll fail 🤦
@IPhonixI3 жыл бұрын
npm run build > api@1.0.0 build D:\Projects\Routin\typscript-express-nodejs-quickstart > rm -rf build && prettier --write source/ && tsc 'rm' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! api@1.0.0 build: `rm -rf build && prettier --write source/ && tsc` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the api@1.0.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\MyCroft\AppData\Roaming pm-cache\_logs\2020-12-12T19_40_12_114Z-debug.log
@TheNerdyCanuck3 жыл бұрын
What shell are you using?
@IPhonixI3 жыл бұрын
@@TheNerdyCanuck VSCode Powershell
@IPhonixI3 жыл бұрын
@@TheNerdyCanuck i tested on git shell too
@IPhonixI3 жыл бұрын
$ npm run build > api@1.0.0 build D:\Projects\Routin\typscript-express-nodejs-quickstart > rm -rf build && prettier --write source/ && tsc source\config\config.ts 307ms source\config\logging.ts 62ms source\controllers\sample.ts 23ms source outes\sample.ts 7ms source\server.ts 50ms Version 1.0.3.0 Syntax: tsc [options] [file ..] Examples: tsc hello.ts tsc --out foo.js foo.ts tsc @args.txt Options: --codepage NUMBER Specify the codepage to use when opening source files. -d, --declaration Generates corresponding .d.ts file. -h, --help Print this message. --mapRoot LOCATION Specifies the location where debugger should locate map files instead of generated locations. -m KIND, --module KIND Specify module code generation: 'commonjs' or 'amd' --noImplicitAny Warn on expressions and declarations with an implied 'any' type. --out FILE Concatenate and emit output to single file. --outDir DIRECTORY Redirect output structure to the directory. --removeComments Do not emit comments to output. --sourcemap Generates corresponding .map file. --sourceRoot LOCATION Specifies the location where debugger should locate TypeScript files instead of source locations. -t VERSION, --target VERSION Specify ECMAScript target version: 'ES3' (default), or 'ES5' -v, --version Print the compiler's version: 1.0.3.0 @ Insert command line options and files from a file.