Trying to build a web server using nodejs
Hello guys, sorry to disturb you all; I'm currently learning how to build a web server locally using nodejs. However, I have some doubts; I don't understand that part on the filePath, what are we trying to do here? Why are we both about only html files? What's happening here please
8 Replies
oh my GOD, just type if else statements 😂
i think u can write it as follows as well, i think it looks better this way
now i assume this is probably setting up the path to the file that the server is about to send.
so , client side can ask for html contents to the server
now these static html files are kept in the views folder
and here it is just setting up the path to the html file that the client is asking for so the server can send to the client
the html file is kept inside the views directory and this is all kept in the server and not in the client. but the server needs to know which html file needs to be sent and WHERE that html file is . the block of code simply sets up that path
__dirname
i believe is the global node variable that contains the path to the current directoryyep I see, why are we only interested in html file, like contentType is only for html
the
pwd
command returns the path to the current directory
it is a shell command
below u can see i am running the js in node , and the js code is just logging out the __dirname
which returns the same thing /home/glutonium/dirname
i am not 100% sure. I don't have too much BE knowledge, but have you checked the full code?
maybe they are checking for other content types somewhere else?hmm the other contents like css/image/js file are handled in the last condition
I understand what the guy try to do but I don't know, it's not that clear in my head ðŸ˜
I didn't get the "Aha" moment in my head 😅
lol. i cant say much without the whole code, assuming i'd understand the whole code at all lol
I can share the video if you want :c
ooh its a video
well naah forget it lol
would've been faster if it was github xD