> For the complete documentation index, see [llms.txt](https://eleven-fifty-academy.gitbook.io/javascript-152-nodeserver/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eleven-fifty-academy.gitbook.io/javascript-152-nodeserver/js_library/node-server/01-server-set-up/03-express-code.md).

# 03 - Express code

In this module we'll make a simple Express server.

## File Structure

Let's go inside of `app.js` in your `server` directory.

```
       Node-Server
            └── server
                └── .gitignore
                └── app.js
```

## Basic Server Code

In `app.js`, go ahead and add the following code:

```javascript
var express = require('express'); //1
var app = express(); //2

//3         //4
app.listen(3000, function(){
    console.log('App is listening on 3000.') //5
});
```

## Analysis

Let's analyze the code:&#x20;

1\. Here we require the use of the `express` npm package that we've installed in our dependencies.&#x20;

2\. We create an instance of express. We're actually firing off a top-level `express()` function, a function exported by the Express module. This allows us to create an Express app.&#x20;

3\. `app.listen` will use express to start a UNIX socket and listen for connections on the given path. This method is identical to Node’s `http.Server.listen()`.&#x20;

4\. The given path is `localhost:3000`.&#x20;

5\. We call a callback function when the connection happens with a simple `console.log`.

## Running the Code

1. Open your terminal in VS Code. Make sure you are in the server directory.
2. Type in `node app.js`.
3. In your console/terminal window, you should see your console message:

   ![screenshot](https://785407262-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfspjIVOP2BrMNl%2F-LAU8cHEwYbpO3Obye5i%2F-LAU8q2QFtrqTsvriNrv%2F03-node-appjs.png?generation=1524162325641862\&alt=media)

   Don't worry about the error message right now. It won't affect anything.
4. When we go to <http://localhost:3000/>, we will see the application running like this:

![screenshot](https://785407262-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfspjIVOP2BrMNl%2F-LAU8cHEwYbpO3Obye5i%2F-LAU8q41o4DYLzl6gZjD%2F03-server-running-dom.png?generation=1524162339239271\&alt=media)

We'll explain this particular screenshot later.
