Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Servers

Does anyone have a good explanation of servers ? I have done the node and Express courses and I sort of understand how servers work but I don't understand how they would work in like a website. If you had a website that was running Express on the Front end and node on the server side does that mean your running two servers on a server ? And how would the front end server be running on a machine that didn't have node installed? And why is it faster to have a server running on the server, sounds like i don't understand them at all ?

4 Answers

Kevin Korte
Kevin Korte
28,148 Points

Neither Node or Express are servers, and you do not have a server running on the client side. You probably understand this, but to build from the ground up, you have a server, which is a computer that is connected to the internet, and can receive requests for data, and respond to them. You have your client side, which is your client's browser, which is able to take html, css, and javascript, and turn it into a website. It's also capable of making requests to servers, and displaying their response.

Node.js, is a language that a server can understand. Node just happens to be written in javascript, the same language your browser understands (javascript), but a browser can not run Node.js. Just because you are running javascript on the server, and javascript on the browser, don't confuse the two they are the same. They're not. They share the same language, but that's it.

Node.js is an open platform, like ruby, or PHP, or python. Node defines who a server can expect requests, interact with those request, and how it should respond.

Express.js also runs on the server, that Node is running one. Express is a framework, much like Rails is a framework for Ruby, Laravel is a framework for PHP, and Django is a framework for python. It gives the developer an way to handle common use case scenarios in a consistent way. That might be how you handle routes, or send views back to the browser. This is common stuff that a framework handles, that a language does not explicitly deal with.

Both node and express, work together to receive request by a browser, do something, and then return something. It just happens to be all in javascrpt. Again, though it's not javascript that would work on a browser

So you don't have a server running on the client side ? I thought I seen that in a course, finding this very confusing.

Kevin Korte
Kevin Korte
28,148 Points

Not by definition, no.

Browsers are sophisticated, but they are not a server.

You don't run node, or express on the client side. All of that is ran on the server side.

So when i use node to create a server is that more of a guide for the server of how to handle the files?