You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2012-11-3-http.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ var server = http.createServer(function (req, res) {
27
27
});
28
28
{% endhighlight %}
29
29
30
-
The callback function `function (req, res) {}` passed into the `createServer` call will be called when every request comes in. It is passed two arguments, the request (readable stream) and the response (writable stream).
30
+
The callback function `function (req, res) {}` passed into the `createServer` call will be invoked with every new request to our server. This callback is passed two arguments, the request (a readable stream) and the response (a writable stream).
31
31
32
32
Our new server is not yet bound to any port, and therefore cannot accept incoming connections. In order to bind to a port, call the `server.listen(port)` function.
33
33
@@ -47,9 +47,9 @@ Let's boot up our server and take a look. Run the script:
47
47
$ node server.js
48
48
{% endhighlight %}
49
49
50
-
Now, open your browser and navigate to [http://localhost:8080](http://localhost:8080). You will notice that your browser seems to hang and will eventually timeout. This is because our server is not yet doing anything useful with the incoming connection (in fact, it's the `// TODO` line).
50
+
Now, open your browser and navigate to [http://localhost:8080](http://localhost:8080). You will notice that your browser seems to hang and will eventually timeout. This is because our server is not yet doing anything useful with the incoming connection.
51
51
52
-
Let's start by responding to all requests with a 200 status code.
52
+
Let's start by responding to all requests with a 200 status code. This is HTTP speak for everything is OK.
53
53
54
54
{% highlight javascript %}
55
55
var http = require('http');
@@ -147,7 +147,7 @@ var templateEngine = function (template, data) {
147
147
};
148
148
{% endhighlight %}
149
149
150
-
`templateEngine` takes a template string and a data object and searches for the pattern `{variableName}` and replaces matches with `data.variableName`. Feel free to copy/paste this code unless you want extra practice writing JavaScript.
150
+
`templateEngine` takes a template string and a data object and searches for the pattern `{variableName}` and replaces matches with `data.variableName`. Feel free to copy/paste this code unless you want extra practice writing JavaScript and regular expressions.
151
151
152
152
Let's use this simple template engine to parse the content of our `index.html` file.
0 commit comments