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 — changes :soon: · bitgord/fullstack-javascript@ad96337

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • 08-test
    • mb-server.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎08-test/mb-server.js‎

Copy file name to clipboardExpand all lines: 08-test/mb-server.js
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var util= require('util')
55
var 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
9+
810
var messages=[]
911
// This array will hold our messages
1012
messages.push({
@@ -17,13 +19,12 @@ exports.server=http.createServer(function (req, res) {
1719
// Creates server
1820
if (req.method == 'POST' && req.url == '/messages/create.json') {
1921
// If method is POST and URL is messages/ add message to the array
20-
var message=''
22+
var message = ''
2123
req.on('data', function(data, msg){
2224
console.log(data.toString('utf-8'))
2325
message=exports.addMessage(data.toString('utf-8'))
2426
// Data is type of Buffer and must be converted to string with encoding UTF-8 first
2527
// Adds message to the array
26-
2728
})
2829
req.on('end', function(){
2930
console.log('message', util.inspect(message, true, null))
@@ -37,25 +38,23 @@ exports.server=http.createServer(function (req, res) {
3738
} else
3839
if (req.method == 'GET' && req.url == '/messages/list.json') {
3940
// If method is GET and URL is /messages output list of messages
40-
var body=exports.getMessages()
41+
var body = exports.getMessages()
4142
// Body will hold our output
4243
res.writeHead(200, {
4344
'Content-Length': body.length,
4445
'Content-Type': 'text/plain'
4546
})
4647
res.end(body)
47-
}
48-
else {
48+
} else {
4949
res.writeHead(200, {'Content-Type': 'text/plain'})
5050
// Sets the right header and status code
5151
res.end('Hello World\n')
52+
// Outputs string with line end symbol
5253
}
53-
console.log(req.method)
5454

55-
// Outputs string with line end symbol
56-
}).listen(process.env.PORT || 1337)
55+
}).listen(port)
5756
// Sets port and IP address of the server
58-
console.log('Server running at http://127.0.0.1:1337/')
57+
console.log('Server running at http://127.0.0.1:%s/', port)
5958

6059

6160
exports.getMessages = function() {

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.