GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — review chapter 6 · LukaszLevy/fullstack-javascript@0c0d336

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • chapter6
    • chapter6.md
  • code
    • 06-hello
      • server.js
    • 06-test
      • mb-server.js
      • test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎chapter6/chapter6.md‎

Copy file name to clipboardExpand all lines: chapter6/chapter6.md
+6-6Lines changed: 6 additions & 6 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ environment or assign 1337 if the environment is not set, use:
7373
This will create a server, and a callback function will contain the
7474
response handler code:
7575

76-
const server = http.createServer(function (req, res) {
76+
const server = http.createServer((req, res) => {
7777

7878
To set the right header and status code, use:
7979

@@ -87,7 +87,7 @@ To output "Hello World" with the line end symbol, use:
8787
To set a port and display the address of the server and the port number,
8888
use:
8989

90-
server.listen(port, function() {
90+
server.listen(port, () => {
9191
console.log('Server is running at %s:%s ',
9292
server.address().address, server.address().port)
9393
})
@@ -179,7 +179,7 @@ include:
179179
- `util.inspect()`: Return a string representation of an object,
180180
which is useful for debugging
181181

182-
###querystring
182+
### querystring
183183

184184
This module provides utilities for dealing with query strings. Some of
185185
the methods include:
@@ -215,22 +215,22 @@ The lists of non-core modules can be found at:
215215
- [npmjs.org](https://npmjs.org): Node Package Manager registry
216216

217217
- Nipster (http://eirikb.github.io/nipster): NPM search
218-
[Nipster](http://eirikb.github.com/nipster/): NPM search tool for
218+
[Nipster](http://eirikb.github.com/nipster): NPM search tool for
219219
Node.js
220220

221221
- [node-modules(http://node-modules.com): npm search engine
222222
](node-modules(http://node-modules.com):%20npm%20search%20engine%20%20%20%20%20)
223223

224224
If you would like to know how to code your own modules, take a look at
225225
the article located here:
226-
https://quickleft.com/blog/creating-and-publishing-a-node-js-module/ .
226+
<https://quickleft.com/blog/creating-and-publishing-a-node-js-module>.
227227

228228
npm Node Package Manager
229229
------------------------
230230

231231
<span id="manager" class="anchor"></span>Node Package Manager, or NPM,
232232
manages dependencies and installs modules for you. Node.js installation
233-
comes with NPM, whose web site is [npmjs.org](http://npmjs.org/).
233+
comes with NPM, whose web site is [npmjs.org](http://npmjs.org).
234234

235235
`package.json` contains meta information about our Node.js application
236236
such as a version number; author name; and, most important, what
Collapse file

‎code/06-hello/server.js‎

Copy file name to clipboard
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
var http = require('http') // Loads http module
1+
const http = require('http') // Loads http module
22

3-
var port = process.env.PORT || 1337
3+
const port = process.env.PORT || 1337
44

5-
var server = http.createServer(function (req, res) { // Creates server
5+
const server = http.createServer((req, res) => { // Creates server
66
res.writeHead(200, {'Content-Type': 'text/plain'}) // Sets the right header and status code
77
res.end('Hello World\n') // Outputs string with line end symbol
88
})
9-
server.listen(port, function() {
10-
console.log('Server is running at %s:%s ', server.address().address, server.address().port) // Sets port and IP address of the server
9+
server.listen(port, () => {
10+
console.log('Server is running at %s:%s ',
11+
server.address().address, server.address().port) // Sets port and IP address of the server
1112
})
Collapse file

‎code/06-test/mb-server.js‎

Copy file name to clipboardExpand all lines: code/06-test/mb-server.js
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var http = require('http')
1+
const http = require('http')
22
// Loads http module
3-
var util= require('util')
3+
const util= require('util')
44
// Usefull functions
5-
var querystring = require('querystring')
5+
const querystring = require('querystring')
66
// Loads querystring module, we'll need it to serialize and deserialize objects and query strings
77

8-
var port = process.env.PORT || 1337
8+
const port = process.env.PORT || 1337
99

10-
var messages = []
10+
const messages = []
1111
// This array will hold our messages
1212
messages.push({
1313
'name': 'John',
@@ -19,7 +19,7 @@ exports.server = http.createServer(function (req, res) {
1919
// Creates server
2020
if (req.method == 'POST' && req.url == '/messages/create.json') {
2121
// If method is POST and URL is messages/ add message to the array
22-
var message = ''
22+
let message = ''
2323
req.on('data', function(data, msg){
2424
console.log(data.toString('utf-8'))
2525
message = exports.addMessage(data.toString('utf-8'))
@@ -37,7 +37,7 @@ exports.server = http.createServer(function (req, res) {
3737
})
3838
} else if (req.method == 'GET' && req.url == '/messages/list.json') {
3939
// If method is GET and URL is /messages output list of messages
40-
var body = exports.getMessages()
40+
const body = exports.getMessages()
4141
// Body will hold our output
4242
res.writeHead(200, {
4343
'Content-Length': body.length,
Collapse file

‎code/06-test/test.js‎

Copy file name to clipboardExpand all lines: code/06-test/test.js
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var http = require('http')
2-
var assert = require('assert')
3-
var querystring = require('querystring')
4-
var util = require('util')
1+
const http = require('http')
2+
const assert = require('assert')
3+
const querystring = require('querystring')
4+
const util = require('util')
55

6-
var messageBoard = require('./mb-server')
6+
const messageBoard = require('./mb-server')
77

88
assert.deepEqual('[{"name":"John","message":"hi"}]',
99
messageBoard.getMessages())

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.