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 Express Basics (2015) Getting Started with Express Your First Express App

Ryan Behrens
Ryan Behrens
1,949 Points

So when we say we are creating a server, what we mean is we are just using the express web framework's library?

I have built express web applications before with tutorials but I am still confused on how it is all working. In a project folder we make an app folder, we require express' module , than assign the module to a variable called app. From there we can use methods like get, post, listen.
then we can set up an http request ( to request from a server...but how does this work?), why do we need to request data from a file that we are writing on?. If we use the app.listen on port whatever...3000, then use app.get('/', function(request, response)) - anonymous callback, then use response's respond method for whatever we want it to say..."hello world", then rerun the server....and local host 3000 will show 'hello world'...how does this work?

where does this server exist? on my computer? is the server my app folder? so my question really boils down to is; It all works because I am using express' framework right? I am setting up ways a user can access my webpage, and I am setting up how to respond to what they type right? by routes? and if they type something wrong i set up an error response yes? this process of how i want to respond to the user is a 'server' ???

2 Answers

Roy Penrod
Roy Penrod
19,810 Points

You are creating the web server using the Express framework. In it's simplest form, a web server is just a program running in the background as a service that listens for an http request and delivers an http response.

The server is the code that you start running before you preview the page.

Anthony c
Anthony c
20,907 Points

This is a great article that explains: http://www.hongkiat.com/blog/node-js-server-side-javascript/

So, first, the word server is thrown around a lot. It can mean two things:

  1. a program that acts as the worker between your browser and (usually) some data storage:
My Database <----> Server <---> Your Browser
  1. the physical computer that that "server program" is on (these are the machines housed by AWS/Cloud Foundry/Modulus/HEROKU, etc)

you can think of it like:

My Database <---> physical server (hardware) <---> server program (software on hardware in random amazon warehouse) <----> your browser

Where do Node and Express come in?

basically:

  • Some servers have a server program called v8, which is a javascript engine (i.e. allows the server to read and execute javascript files)

  • this "engine" is called v8 (or the v8 "environment")

  • node is ran on this engine (which is run on that physical server)

So, we can expand on the above model and visualize it like:

My Database <-> physical server (hardware) <-> server program (software program) <-> Node <--> your browser
  • express is a framework written in "node" (javascript)

  • express is to node what bootstrap is to css/html-- it's basically just a bunch of code that somebody already typed so that we don't have to re-type it ourselves

  • So you could think of things like this:

DATABASE <-> SERVER (hardware) <-> SERVER (software/v8) <-> NODE <-> EXPRESS <-> BROWSER

So you're using express to tell node to talk to the server which is than talking to the database to store users, etc.