Your First Node.js Web Server
HTML-код
- Опубликовано: 22 авг 2024
- In this video I am going to walk you through all the steps necessary to create your very first Node.js web server. We will start at the very beginning with installing Node.js, and end with a fully functioning basic web server that serves HTML documents.
Download Node.js:
nodejs.org/en/
More Node.js Tutorials:
• Your First Node.js Web...
Twitter:
/ devsimplified
GitHub:
github.com/Web...
CodePen:
codepen.io/Web...
#Nodejs #WebDevelopment #WebServer
Here is the link to the Node.js download site. nodejs.org/en/
how do you get the node terminal? i cant seem to get it
@@andrewbailey8378 Dear, it's not "node terminal". He is on Windows and he uses a bash shell that is provided by git terminal. That "node terminal" doesn't show that it is "node terminal", it shows the process that is currently running in the terminal. In our case, it is node, because we started a node server, but it can be any other process.
@@vladimirmikulic7860 Some problem! I just installed Node.js and I have GIT bash terminal in Visual Code, but when I run the node app.js command it gives and error bash: node: command not found
@@Jokamutta are you on Windows?
@@vladimirmikulic7860 Yea I am
I was adamant to find a simple explanation after browsing 30+ complex tutorials for 4 days. Thank you so much for this!
Same here , exactly what i was thinking
same here
Kyle, I wish you made tutorials for everything in life. Always long enough to learn something, short enough for my potato-like attention span to handle, and clear enough for anyone to understand. Great stuff!
If you're ALSO just getting started with VS code like me and you're troubleshooting:
1. Make sure the terminal type is set to git bash
2. Do not forget to SAVE before running stuff
Another major thing is at 0:25 - Learn on a rock-solid version
Students can waste time and get discouraged because they don't know the difference between their bugs and a buggy compiler/interpreter.
I had an early Microsoft Pascal IDE that was fun to use but I wasted half my time on a few unsolvable bugs instead of a bunch of finished code. I can't even say "but in the long run I'm a better..." because what I learned was IDE specific, not general debugging.
This was the perfect introduction to Node, you explain soo well! I just watched and understood what was happening in my first viewing, and then coded along the 2nd time. It went incredibly smoothly. Thanks a lot, Kyle. Love learning from you 😊
Have scoured YT for a simple explanation on why I should use Node and how it serves as another web server, and you did it in 9 minutes compared to many videos explaining details we don't need initially to understand why use Node! Man! You really are a great teacher, you have that talent to explain complicated things in a very simple way!
Most RUclips resources for coding are horrible about getting to the point. You get waterboarded with irrelevant esoteric information and get a convoluted explanation trying to demonstrate why something works in an abstract way, as opposed to showing you what the outputs of the code are and explaining it backwards from there. Its like they forget these lessons are for people coming in new to a concept
Just found your channel, I'm a python programmer and wanting to understand more about Node.js and JS in general, your content is really good! Keep it up!
how to get the port number
@@bhaskardhanavath6650 You define the port number when using the server.listen() method, like server.listen(3000, callback). As he did on the video, you can also assign the port to a variable, say "port", and use it on the .listen() method instead.
How to get that port number like 3000 is it system port number
@@bhaskardhanavath6650 You can give any port number you want. example: 9090 , 4000, 2890 etc...
Haha try python flask
thanks for being straightfoward. so many tutorials are unnecessarily long and complex.
Hardly ever found a better startup tutorial on nodejs. Absolutely perfect.
My favourite channel...❤️
He teaches straight forward and no bullshit talks and very clean code...
Brad traversy would be my 2nd fvt channel
The best “hello node” type of Node.js I’ve seen yet.
This was the best http module tutorial. Everywhere else I just found them explaining the functions but didn't connect them with the actual web server. This was awesome! Just what I wanted! Thanks a lot!
thank you... much better than the 4-hour lecture by my teacher in the bootcamp...
Your tutorials are simply great, to the point and easy to understand. Thank you !! I am hooked into watching more and more !!
this is amazing thx so much you just help a 12 years old boy that his dream is to be a programer
I'm younger and am already a programmer. (Please take no offense.)
@@warrennova2575 me too (same. please don't insult me)
@@warrennova2575 knowing some code doesn't make you a programmer. He's talking about programming as a career, and if he's starting at 12 he's already ahead of most of his future peers.
I was just born and I am a programmer
@@sandevabeykoon2398 pfff, I am a spermatozoon and i am already a Senior Software Engineer at the Google
I really enjoyed all your Tutorials about web development. Because i have a background of Dot Net. When am new to wed development i started directly developed my portfolio website with minimum knowledge later realized i have not learn properly, that time i started to watch your videos that are east to understand .Now i started your full-stack development course. Am eager to follow the course. Thank you
Thank you so much! VERY good tutorial and no unnecessary talking, but straight to the point! Really appreciate that and it helped me big time :)
This was a great start for me Kyle, very good content!
Brilliant tutorial! Explained really well, and in a simple way!
THAT was incredibly simple BECAUSE you are an INCREDIBLE teacher, thank you!
So helpful and concise! Thank you so much for sharing!! You really are a gifted teacher.
Thank you for this man, you help me a lot with this video, clean and easy to do.
I have been subbed since I discovered this channel
♥♥ Love your vids
You owned my respect, you got a subscriber! I wish you made tutorials for everything.
Thank you very much for sharing these tutorials. Appreciate all your efforts. It's been very helpful for me! Thank you again!
Your video was concise and right on point. Helped me understand better.
For those saying it doesnt open their website, having them in the solution directory is not enough. You have to parse the request to handle the content type based on the extension. Remember, a bare server request with no file should always default to the home page.
This dude is actually so good at his job lmao.
I love you!
I searched 16 days in the internet to know to how i can render code from a file!
Sorry for my bad english
I love your content and comitment beeing a youtube webDev mentor. I'm on a way to become a junior fullStack and I find your videos very, very usefull. BTW im sth about B1-B2 eng speaker and I fully understand you. Cheers to your success and a bright future! :)
LOL at the browser history at 5:05
Thanks bro my interest in coding has returned.❤
How to auto restart server:
1. In the terminal, run “npm I -save-dev nodemon”
2. In the package.json file, in the “scripts”: create a new key called “devStart” with a value of “nodemon server.js”
3. Create a server.js file
4. In the terminal, run “npm run devStart”
Now every time you save server.js the server will restart
4:56 how to run js code in browser
Or you came just Run "npm install -g nodemon"
@@littleprincess250 open the browser and enter localhost: and the port number that you assigned it in the code
for example, if i set const port = 8080
i will write localhost:8080 in the browser and code will run in browser
Thank you so much. I've been looking at a lot of videos but this one really helped!
I had a problem with using 'node app.js' in the terminal as the command was not recognized. I reinstalled node js and it worked. Just in case anyone else is having this problem.
I have the same problem but it refused to work even after reinstalling node js
@@chimexboy96leo12 try installing the node.js in root directory with the help of command tools or try going to the folder you installed node.js in terminal and then try node cammand. Hope this helps :)
Install node.js in Drive C
This is really an awesome lecture!
you rock dude. this helped me with an intranet (offline) system i'm developing for work.
awesome! clear and concise vid. Just what I need. Thanks
This was made beautifully simple. Perfectly done. Thank you. 🙏
Really easy and simple not to much nonsense for beginners ears...thanks a bunch!
How did you open the browser from vscode to display your output? Is the a special button in vscode, or did you just open a browser and type in localhost3000 instead of a website to get the vscode output to display in the browser?
Awesome! Thank you! :)
ur the best ever.Keep on making good content.Seriously this helped a lot!
Dude you are awesome!! it was easy to understand thank you man!!✌
Excellent video it all made sense !!!
Super vid, real quick clear presentation, good job
Great video as always Kyle!
congrats on 2k kyle
Thanks! I am still in shock from hitting 1k.
Now almost 400k :)
@@w1nGsEEEhTV for real tho lol
Fuckin A. Lean and minimal - perfect for a beginner - no distracting BS!
Thanks! Done setup my first NodeJS server!!!
Thank you for this easy to learn tutorial
I want to add css but how
Cool tutorial man. The node app.js didn't show in the Terminal at first, had to install npm then everything worked!
This is what we call Node.js, not some other install the package bs
Wow you are a pro kyle and you explained very well! Thanks and it works
💗💗💗❤❤❤❤
Perfect explanation, thanks so much!
Funny. All the tutorials are the same. I need minimal example how to send JSON request from browser and respond to browser from node js. Response from node js should not be immidiate but after node js finishes some work and prepare response. Anybody???
Thanks a lot brother. it is working. Keep it up
I just realized that most coder's voices sound the exact same XD
manly
Thanks a lot man for helping me out.
nice hair style and nice code!
Love u broo.. u really made me to get interest in js.. thanks a lot..
What a great video! Thumbs up :)
I'm getting "Error: File Not Found." not sure why?
That was quick? WOW!
This is extremely good! Thumbs up from Brasil !! ;)
Much thanks, this helped a lot
Great content. Thanks for the effort.
You are a genius. thank you for this video
you really Simplified the nodejs. Do you have any plan to create a nodeJS Crash Course?
SO VERY HELPFUL
Awesome tutorial :)
Really very helpful... thank you very much
I Remember when you where at 104k Subs
very helpful, thank you!
what is the difference between this node server and apche/nginx ?
Cool to know this manual method. The Live server Extension on VS Code works in the same way right?
Not really. Live server just sets up a really basic server but doesn't allow you to do any server side code with it. Node.js on the other hand allows you to write a ton of custom server side code.
Your Mad...... I loved how you explained... thankx :)
Thank you bro, God bless you!
Helpful video 👍😘
5:03 I got scared at first from that sound
It was a great tutorial.....It will be great if you could make a video on how to structure a nodejs backend. Since i could not find it anywhere . Thanks
I am in love with your videos lol
Great tutorial, but the syntax you are using in this video is giving errors..
I had to rewrite my code to look like this so that it can work:
import { createServer } from 'http'
const port = 3000;
const server = createServer((req, res) => {
res.write('Hello Node!')
res.end()
})
server.listen(port, () => {
console.log('Server running on port ' + port)
});
4:56 how to run js code in browser
thanks yo !! you help me a lot
Nice video, thanks a lot
How do you run node on the browser?
you have amazing hair
Thanks!
@@WebDevSimplified bro how do add CSS and javascript?
@@BlackUp1217 just link those file in html
thanks so much very helpful
Awesome work 👍
how can I serve css and js files on the server next to the index.html ?
I think u need to href on index. html file itself, no need to again mention it on node server
Hi, if you planning to server the other files you need to have multiple if else conditions, actually here he just showed how to use the http module to to host a simple http server.
if you are planning to use for production, I suggest to use some http server module. But for learning purpose you can create if-else-if conditions like give here ruclips.net/video/ylrWqPadP58/видео.html
@@itarticles6338 Hi, I figured out how to do it for what I was looking for. It was not this. I wanted to run my project on tablet or from from my computer and you can do that with live server from node and find your ip and log with it in the browser and there is your website from the computer now on the phone ore tablet
@@Pe30Beat perfect, yes thats the way, although it will work if you are connected to same network. If you are looking for cross network sharing, there are few node module you can use, they create secure tunnel to your machine and provide your dynamic url, and you can share that URL with anyone in this universe. Happy Coding.
@@itarticles6338 thanks for the info
The good and the simple one!
The part that should show, when an error happens, does not work... It doesn't make sense to send a 200 before the error check is done. So the "fs.readFile" line (line 6) has to be moved inside the "if(error) {} else { " section. then you also get a proper error feedback.
Was stuck for long time 'ERR_STREAM_WRITE_AFTER_END'. and your comment helped. Thanks a lot
Thank you very much
nerds are such chads
Very well explained. How de you add the CSS and JavaScript to the index.html file in this server?
ezy as u do in html
@@newagecoder5417 that doesn't work for me
@@LosEspookys wts your css file name? Or the file is in any folder??
it's amazing explaination, but I have a question; why did you write res.writeHead(200, { content-type: "text/html"}) outside the callback function, not inside the else statement?
good video for beginer
Thank you!
I wonder how you add URLs. Great video! Nice and simple just like I like it. Thanks.
What do you mean "add URLS"? do you mean to link something in the site or to deploy the website onto a hosting platform?
Thanks, Kyle.