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

<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>

(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

&lt;pre&gt; var config = { foo: &#039;foo&#039;, goo: &#039;goo&#039; } module.exports = config; &lt;/pre&gt;


app.js

&lt;pre&gt; var config = require(&#039;./config&#039;) var express = require(&#039;express&#039;) var app = express()

var log = function (req, res, next) { console.log(req.ip + &quot; --&gt; &quot; + req.path) next() } app.use(log);

app.get(&#039;/foo&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;May 10, 2017&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.foo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;) })

app.get(&#039;*&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;May 10, 2017&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.goo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;) })

app.listen(8888, function () { console.log(&#039;Server listening on port 8888!&#039;) }) &lt;/pre&gt;

(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: &#039;foo&#039;, goo: &#039;goo&#039;

} module.exports = config;

var express = require(&#039;express&#039;) var config = require(&#039;./config&#039;)

var app = express()

var log = function (req, res, next) { console.log(req.ip) next() } app.use(log); app.get(&#039;/foo&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;I class excersise&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.foo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;) }) app.get(&#039;*&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;In Class Excersise&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.goo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;) }) app.listen(8888, function () { console.log(&#039;Server listening on port 8888&#039;) })

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: &#039;Entered foo!&#039;, goo: &#039;You got goo instead&#039; } module.exports = config;

app.js var express = require(&#039;express&#039;); var app = express(); var config = require(&#039;./config&#039;);

var logger = function (req, res, next) { console.log(&quot;IP: &quot; + req.ip); next(); } app.use(logger);

app.listen(8888, function () { console.log(&#039;Server up!&#039;) })

app.get(&#039;/foo&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Foo Page&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.foo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;); })

app.get(&#039;/*&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Goo Page&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.goo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;); })

app.get(&#039;/&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Goo Page&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.goo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;); })

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: &#039;foo&#039;, goo: &#039;goo&#039; } module.exports = config;

app.js

var config = require(&#039;./config&#039;); var express = require(&#039;express&#039;); var app = express();

var log = function(req, res, next) { console.log(req.ip); next(); } app.use(log);

app.get(&#039;/foo&#039;,function(req, res) { res.send(&#039;!&lt;DOCTYPE html&gt;&lt;html&gt;&lt;body&gt;&#039;+config.foo+&#039;&lt;/body&gt;&lt;/html&gt;&#039;) })

app.get(&#039;*&#039;,function(req, res) { res.send(&#039;!&lt;DOCTYPE html&gt;&lt;html&gt;&lt;body&gt;&#039;+config.goo+&#039;&lt;/body&gt;&lt;/html&gt;&#039;) });

app.listen(8888 ,function() { console.log(&#039;Listening to port 8888.&#039;) });

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 = { &quot;foo&quot;: &quot;foo&quot;, &quot;goo&quot;: &quot;goo&quot;, } module.exports = config; -------expressapp.js---------- var express = require(&#039;express&#039;); var config = require(&#039;./config&#039;); var app = express();

var logger = function (req, res, next) { console.log(req.ip); next() } app.use(logger);

app.get(&#039;/foo&#039;, function(req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;May 10 In Class Exercise&lt;/title&gt;
&lt;/head&gt;&lt;body&gt;&#039; + config.foo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;) })

app.get(&#039;*&#039;, function(req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;May 10 In Class Excersise&lt;/title&gt; &lt;/head&gt;&lt;body&gt;&#039; + config.goo +&#039;&lt;/body&gt;&lt;/html&gt;&#039;) })

app.listen(8888, function () { console.log(&#039;Server up!&#039;) })

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

&#039;&#039;&#039;Michael Nguyen&#039;&#039;&#039;

&lt;pre&gt; config.js

var config = { &quot;foo&quot;: &quot;foo&quot;, &quot;goo&quot;: &quot;goo&quot; }; module.exports = config;

index.ejs &lt;!DOCTYPE html&gt; &lt;html&gt;

&lt;head&gt; &lt;title&gt;In-class Exercise&lt;/title&gt; &lt;/head&gt;

&lt;body&gt; &lt;h1&gt; &lt;%=value%&gt; &lt;/h1&gt; &lt;/body&gt;

&lt;/html&gt;

app.js

var express = require(&#039;express&#039;);

var path = require(&#039;path&#039;); // for directory paths var config = require(path.join(__dirname, &#039;config&#039;));

var app = express();

// view engine setup app.set(&#039;views&#039;, path.join(__dirname, &#039;views&#039;)); app.set(&#039;view engine&#039;, &#039;ejs&#039;);

// create logger var logger = function(req, res, next) { console.log(req.ip + &quot;: &quot; + req.method); next(); } app.use(logger);

// can add different routes app.get(&#039;/foo&#039;, function(req, res) { res.render(&#039;index&#039;, { &#039;value&#039;: config.foo }); }); // route for everything else app.get(&#039;/*&#039;, function(req, res) { res.render(&#039;index&#039;, { &#039;value&#039;: config.goo }); });

app.listen(8888, function() { console.log(&#039;Server up!&#039;) }); &lt;/pre&gt;

(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(&#039;express&#039;); var app = express(); var config = require(&#039;./config&#039;)

var log= function(req, res, next){ console.log(req.ip + &quot; -&gt; &quot; + req.path) next() } app.use(log); app.get(&#039;/foo&#039;, function(req, res){ res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;in class 5/10&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.foo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;) })

app.get(&#039;*&#039;, function(req, res){ res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;in class 5/10&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.goo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;) })

app.listen(8888, function () { console.log(&#039;Server up!&#039;) })

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 &lt;nowiki&gt; var config = require(&#039;./config&#039;) var express = require(&#039;express&#039;); var app = express();

var log = function (req, res, next) { console.log(req.ip + &quot; --&gt; &quot; + req.path) next()

}; app.use(log);

app.get(&#039;/foo&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;app&lt;/title&gt;&lt;meta charset=&quot;utf-8&quot; /&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.foo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;)

});

app.get(&#039;*&#039;, function (req, res) { res.send(&#039;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;app&lt;/title&gt;&lt;meta charset=&quot;utf-8&quot; /&gt;&lt;/head&gt;&lt;body&gt;&#039; + config.goo + &#039;&lt;/body&gt;&lt;/html&gt;&#039;)

});

app.listen(8888, function () { console.log(&#039;Server listening on port 8888! Go to http://localhost:3000&#039;)

}); &lt;/nowiki&gt;

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