2017-05-10

May 10 In-Class Exercise.

Post your solutions to the May 8 In-Class Exercise to this thread.
Best, Chris
(Edited: 2017-05-10)
Post your solutions to the May 8 In-Class Exercise to this thread. Best, Chris

-- May 10 In-Class Exercise
var express = require('express');
var app = express();
var config = require('./config'); 
 
var log = function(req, res, next) {
    console.log(req.ip + " --> " + req.path)
	next()
}    app.use(log);    app.get('/*foo*', function(req, res) {     res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.foo + '</h1></body></html>'); });    app.get('/', function(req, res) {     res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.goo + '</h1></body></html>'); });    app.get('/*', function(req, res) {     res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.goo + '</h1></body></html>'); })    app.listen(8888, function () {     console.log('Listening on port 8888'); }) (Edited: 2017-05-10)
<pre> var express = require('express'); var app = express(); var config = require('./config'); var log = function(req, res, next) { console.log(req.ip + " --> " + req.path) next() } app.use(log); app.get('/*foo*', function(req, res) { res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.foo + '</h1></body></html>'); }); app.get('/', function(req, res) { res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.goo + '</h1></body></html>'); }); app.get('/*', function(req, res) { res.send('<!DOCTYPE HTML><html><head><title>test</title></head><body><h1>' + config.goo + '</h1></body></html>'); }) app.listen(8888, function () { console.log('Listening on port 8888'); }) </pre>

-- May 10 In-Class Exercise
config.js
var config = {
	foo: 'foo',
	goo: 'goo'
} module.exports = config;

app.js
var config = require('./config')
var express = require('express')
var app = express() 
 
var log = function (req, res, next) {
	console.log(req.ip + " --> " + req.path)
	next()
} app.use(log);    app.get('/*foo*', function (req, res) {
	res.send('<!DOCTYPE html><html><head><title>May 10, 2017</title></head><body>' + config.foo + '</body></html>')
})    app.get('*', function (req, res) {
	res.send('<!DOCTYPE html><html><head><title>May 10, 2017</title></head><body>' + config.goo + '</body></html>')
})    app.listen(8888, function () {
	console.log('Server listening on port 8888!')
}) (Edited: 2017-05-10)
config.js <pre> var config = { foo: 'foo', goo: 'goo' } module.exports = config; </pre> ---- app.js <pre> var config = require('./config') var express = require('express') var app = express() var log = function (req, res, next) { console.log(req.ip + " --> " + req.path) next() } app.use(log); app.get('/*foo*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>May 10, 2017</title></head><body>' + config.foo + '</body></html>') }) app.get('*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>May 10, 2017</title></head><body>' + config.goo + '</body></html>') }) app.listen(8888, function () { console.log('Server listening on port 8888!') }) </pre>

-- May 10 In-Class Exercise
Richard Lack
config.js var config = {
	foo: 'foo',
	goo: 'goo'
} module.exports = config;
var express = require('express') var config = require('./config')
var app = express()
var log = function (req, res, next) {
	console.log(req.ip)
	next()
} app.use(log); app.get('/*foo*', function (req, res) {
	res.send('<!DOCTYPE html><html><head><title>I class excersise</title></head><body>' + config.foo +
	 '</body></html>')
}) app.get('*', function (req, res) {
	res.send('<!DOCTYPE html><html><head><title>In Class Excersise</title></head><body>' + config.goo +
	 '</body></html>')
}) app.listen(8888, function () {
	console.log('Server listening on port 8888')
})
Richard Lack config.js var config = { foo: 'foo', goo: 'goo' } module.exports = config; var express = require('express') var config = require('./config') var app = express() var log = function (req, res, next) { console.log(req.ip) next() } app.use(log); app.get('/*foo*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>I class excersise</title></head><body>' + config.foo + '</body></html>') }) app.get('*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>In Class Excersise</title></head><body>' + config.goo + '</body></html>') }) app.listen(8888, function () { console.log('Server listening on port 8888') })

-- May 10 In-Class Exercise
config.js
 var config = {
     foo: 'Entered foo!',
     goo: 'You got goo instead'
 }
 module.exports = config;
app.js
 var express = require('express');
 var app = express();
 var config = require('./config');
 var logger = function (req, res, next) {
   console.log("IP:  " + req.ip);
   next();
 }
 app.use(logger);
 app.listen(8888, function () {
   console.log('Server up!')
 })
 app.get('/*foo*', function (req, res) {
   res.send('<!DOCTYPE html><html><head><title>Foo Page</title></head><body>' + config.foo + '</body></html>');
 })
 app.get('/*', function (req, res) {
   res.send('<!DOCTYPE html><html><head><title>Goo Page</title></head><body>' + config.goo + '</body></html>');
 })
 app.get('/', function (req, res) {
   res.send('<!DOCTYPE html><html><head><title>Goo Page</title></head><body>' + config.goo + '</body></html>');
 })
config.js var config = { foo: 'Entered foo!', goo: 'You got goo instead' } module.exports = config; app.js var express = require('express'); var app = express(); var config = require('./config'); var logger = function (req, res, next) { console.log("IP: " + req.ip); next(); } app.use(logger); app.listen(8888, function () { console.log('Server up!') }) app.get('/*foo*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>Foo Page</title></head><body>' + config.foo + '</body></html>'); }) app.get('/*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>Goo Page</title></head><body>' + config.goo + '</body></html>'); }) app.get('/', function (req, res) { res.send('<!DOCTYPE html><html><head><title>Goo Page</title></head><body>' + config.goo + '</body></html>'); })

-- May 10 In-Class Exercise
config.js
var config = {
	foo: 'foo',
	goo: 'goo'
} module.exports = config;
app.js
var config = require('./config'); var express = require('express'); var app = express();
var log = function(req, res, next) {
	console.log(req.ip);
	next();
} app.use(log);
app.get('/*foo*',function(req, res) {
	res.send('!<DOCTYPE html><html><body>'+config.foo+'</body></html>')
})
app.get('*',function(req, res) {
	res.send('!<DOCTYPE html><html><body>'+config.goo+'</body></html>')
});
app.listen(8888 ,function() {
	console.log('Listening to port 8888.')
});
config.js ---- var config = { foo: 'foo', goo: 'goo' } module.exports = config; app.js ---- var config = require('./config'); var express = require('express'); var app = express(); var log = function(req, res, next) { console.log(req.ip); next(); } app.use(log); app.get('/*foo*',function(req, res) { res.send('!<DOCTYPE html><html><body>'+config.foo+'</body></html>') }) app.get('*',function(req, res) { res.send('!<DOCTYPE html><html><body>'+config.goo+'</body></html>') }); app.listen(8888 ,function() { console.log('Listening to port 8888.') });

-- May 10 In-Class Exercise
Xincheng Yuan
----Config.js---------
 var config = {
    "foo": "foo",
    "goo": "goo",
 }
 module.exports = config;

---expressapp.js----------
 var express = require('express');
 var config = require('./config');
 var app = express();
 
 var logger = function (req, res, next) { 
  console.log(req.ip);
  next()
 }
 app.use(logger);
 app.get('/*foo*', function(req, res) {
  res.send('<!DOCTYPE html><html><head><title>May 10 In Class Exercise</title>   
  </head><body>' + config.foo + '</body></html>')
  })
 app.get('*', function(req, res) {
 res.send('<!DOCTYPE html><html><head><title>May 10 In Class Excersise</title> 
 </head><body>' + config.goo +'</body></html>')
 })
 app.listen(8888, function () {
    console.log('Server up!')
 })
Xincheng Yuan --------Config.js--------- var config = { "foo": "foo", "goo": "goo", } module.exports = config; -------expressapp.js---------- var express = require('express'); var config = require('./config'); var app = express(); var logger = function (req, res, next) { console.log(req.ip); next() } app.use(logger); app.get('/*foo*', function(req, res) { res.send('<!DOCTYPE html><html><head><title>May 10 In Class Exercise</title> </head><body>' + config.foo + '</body></html>') }) app.get('*', function(req, res) { res.send('<!DOCTYPE html><html><head><title>May 10 In Class Excersise</title> </head><body>' + config.goo +'</body></html>') }) app.listen(8888, function () { console.log('Server up!') })

-- May 10 In-Class Exercise
Michael Nguyen
config.js

--- var config = {     "foo": "foo",     "goo": "goo" }; module.exports = config;
-- index.ejs <!DOCTYPE html> <html>    <head>     <title>In-class Exercise</title> </head>    <body>     <h1>         <%=value%>     </h1> </body>    </html>
-- app.js
-- var express = require('express');    var path = require('path'); // for directory paths var config = require(path.join(__dirname, 'config'));    var app = express();    // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs');    // create logger var logger = function(req, res, next) {     console.log(req.ip + ": " + req.method);     next(); } app.use(logger);    // can add different routes app.get('/*foo*', function(req, res) {     res.render('index', { 'value': config.foo }); }); // route for everything else app.get('/*', function(req, res) {     res.render('index', { 'value': config.goo }); });    app.listen(8888, function() {     console.log('Server up!') });
(Edited: 2017-05-10)
'''Michael Nguyen''' <pre> config.js ------- var config = { "foo": "foo", "goo": "goo" }; module.exports = config; ------ index.ejs <!DOCTYPE html> <html> <head> <title>In-class Exercise</title> </head> <body> <h1> <%=value%> </h1> </body> </html> ------ app.js ------ var express = require('express'); var path = require('path'); // for directory paths var config = require(path.join(__dirname, 'config')); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // create logger var logger = function(req, res, next) { console.log(req.ip + ": " + req.method); next(); } app.use(logger); // can add different routes app.get('/*foo*', function(req, res) { res.render('index', { 'value': config.foo }); }); // route for everything else app.get('/*', function(req, res) { res.render('index', { 'value': config.goo }); }); app.listen(8888, function() { console.log('Server up!') }); </pre>

-- May 10 In-Class Exercise
Loan Vo
var express = require('express'); var app = express(); var config = require('./config')
var log= function(req, res, next){
	console.log(req.ip + " -> " + req.path)
	next() 
} app.use(log); app.get('/*foo*', function(req, res){
	res.send('<!DOCTYPE html><html><head><title>in class 5/10</title></head><body>' + config.foo + '</body></html>')
})
app.get('*', function(req, res){
	res.send('<!DOCTYPE html><html><head><title>in class 5/10</title></head><body>' + config.goo + '</body></html>')
})
app.listen(8888, function () {
    console.log('Server up!')
})
Loan Vo var express = require('express'); var app = express(); var config = require('./config') var log= function(req, res, next){ console.log(req.ip + " -> " + req.path) next() } app.use(log); app.get('/*foo*', function(req, res){ res.send('<!DOCTYPE html><html><head><title>in class 5/10</title></head><body>' + config.foo + '</body></html>') }) app.get('*', function(req, res){ res.send('<!DOCTYPE html><html><head><title>in class 5/10</title></head><body>' + config.goo + '</body></html>') }) app.listen(8888, function () { console.log('Server up!') })

-- May 10 In-Class Exercise
David Lerner var config = require('./config') var express = require('express'); var app = express(); var log = function (req, res, next) { console.log(req.ip + " --> " + req.path) next() }; app.use(log); app.get('/*foo*', function (req, res) { res.send('app' + config.foo + '') }); app.get('*', function (req, res) { res.send('app' + config.goo + '') }); app.listen(8888, function () { console.log('Server listening on port 8888! Go to http://localhost:3000') });
David Lerner <nowiki> var config = require('./config') var express = require('express'); var app = express(); var log = function (req, res, next) { console.log(req.ip + " --> " + req.path) next() }; app.use(log); app.get('/*foo*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>app</title><meta charset="utf-8" /></head><body>' + config.foo + '</body></html>') }); app.get('*', function (req, res) { res.send('<!DOCTYPE html><html><head><title>app</title><meta charset="utf-8" /></head><body>' + config.goo + '</body></html>') }); app.listen(8888, function () { console.log('Server listening on port 8888! Go to http://localhost:3000') }); </nowiki>
[ Next ]
X