diff --git a/10_Requests/.settings/launch.json b/10_Requests/.settings/launch.json new file mode 100644 index 0000000..f5346f0 --- /dev/null +++ b/10_Requests/.settings/launch.json @@ -0,0 +1,40 @@ +{ + "version": "0.1.0", + // List of configurations. Add new configurations or edit existing ones. + // ONLY "node" and "mono" are supported, change "type" to switch. + "configurations": [ + { + // Name of configuration; appears in the launch configuration drop down menu. + "name": "Launch app.js", + // Type of configuration. Possible values: "node", "mono". + "type": "node", + // Workspace relative or absolute path to the program. + "program": "app.js", + // Automatically stop program after launch. + "stopOnEntry": false, + // Command line arguments passed to the program. + "args": [], + // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace. + "cwd": ".", + // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. + "runtimeExecutable": null, + // Optional arguments passed to the runtime executable. + "runtimeArgs": [], + // Environment variables passed to the program. + "env": { }, + // Use JavaScript source maps (if they exist). + "sourceMaps": false, + // If JavaScript source maps are enabled, the generated code is expected in this directory. + "outDir": null + }, + { + "name": "Attach", + "type": "node", + // TCP/IP address. Default is "localhost". + "address": "localhost", + // Port to attach to. + "port": 5858, + "sourceMaps": false + } + ] +} diff --git a/10_Requests/app.js b/10_Requests/app.js new file mode 100644 index 0000000..edb6e68 --- /dev/null +++ b/10_Requests/app.js @@ -0,0 +1,25 @@ +var request = require("request"); +var fs = require("fs"); +//Example 1 : Let's grab a page +request("http://www.bing.com", function(error, response, body) { + if (!error && response.statusCode == 200) { + console.log(body) // Show the HTML for the Bing homepage. + } + +}); + +//Example 2 : Simple Download of a file , kinda with no callback +/* +request('http://i.ytimg.com/vi/HrnBrOytj-A/0.jpg').pipe(fs.createWriteStream('rami.jpg')); +*/ + +/* +// Example 3: We can download a file, and capture when its done withe finish event +var file = fs.createWriteStream('rami.jpg'); +request('http://i.ytimg.com/vi/HrnBrOytj-A/0.jpg').pipe(file); +file.on('finish',function(){ + console.log("Okay, we got this stellar pic of Rami"); +}) + +*/ + diff --git a/10_Requests/package.json b/10_Requests/package.json new file mode 100644 index 0000000..7454c50 --- /dev/null +++ b/10_Requests/package.json @@ -0,0 +1,14 @@ +{ + "name": "requests", + "version": "1.0.0", + "description": "Demo for Requests", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "request": "^2.60.0" + } +} diff --git a/11_ExpressMultiple/.settings/launch.json b/11_ExpressMultiple/.settings/launch.json new file mode 100644 index 0000000..3b6aa0a --- /dev/null +++ b/11_ExpressMultiple/.settings/launch.json @@ -0,0 +1,40 @@ +{ + "version": "0.1.0", + // List of configurations. Add new configurations or edit existing ones. + // ONLY "node" and "mono" are supported, change "type" to switch. + "configurations": [ + { + // Name of configuration; appears in the launch configuration drop down menu. + "name": "Launch ./bin/www", + // Type of configuration. Possible values: "node", "mono". + "type": "node", + // Workspace relative or absolute path to the program. + "program": "./bin/www", + // Automatically stop program after launch. + "stopOnEntry": false, + // Command line arguments passed to the program. + "args": [], + // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace. + "cwd": ".", + // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. + "runtimeExecutable": null, + // Optional arguments passed to the runtime executable. + "runtimeArgs": [], + // Environment variables passed to the program. + "env": { }, + // Use JavaScript source maps (if they exist). + "sourceMaps": false, + // If JavaScript source maps are enabled, the generated code is expected in this directory. + "outDir": null + }, + { + "name": "Attach", + "type": "node", + // TCP/IP address. Default is "localhost". + "address": "localhost", + // Port to attach to. + "port": 5858, + "sourceMaps": false + } + ] +} diff --git a/11_ExpressMultiple/app.js b/11_ExpressMultiple/app.js new file mode 100644 index 0000000..4d09ded --- /dev/null +++ b/11_ExpressMultiple/app.js @@ -0,0 +1,62 @@ +var express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); + +var routes = require('./routes/index'); +var users = require('./routes/users'); +var places = require('./routes/places'); + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'jade'); + +// uncomment after placing your favicon in /public +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', routes); +app.use('/users', users); +app.use('/places', places); + +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// error handlers + +// development error handler +// will print stacktrace +if (app.get('env') === 'development') { + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: err + }); + }); +} + +// production error handler +// no stacktraces leaked to user +app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: {} + }); +}); + + +module.exports = app; diff --git a/11_ExpressMultiple/package.json b/11_ExpressMultiple/package.json new file mode 100644 index 0000000..81e4ad7 --- /dev/null +++ b/11_ExpressMultiple/package.json @@ -0,0 +1,17 @@ +{ + "name": "14_JadeExtendBlock", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "body-parser": "~1.13.2", + "cookie-parser": "~1.3.5", + "debug": "~2.2.0", + "express": "~4.13.1", + "jade": "~1.11.0", + "morgan": "~1.6.1", + "serve-favicon": "~2.3.0" + } +} \ No newline at end of file diff --git a/11_ExpressMultiple/public/stylesheets/style.css b/11_ExpressMultiple/public/stylesheets/style.css new file mode 100644 index 0000000..9453385 --- /dev/null +++ b/11_ExpressMultiple/public/stylesheets/style.css @@ -0,0 +1,8 @@ +body { + padding: 50px; + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; +} + +a { + color: #00B7FF; +} diff --git a/11_ExpressMultiple/routes/index.js b/11_ExpressMultiple/routes/index.js new file mode 100644 index 0000000..2be0974 --- /dev/null +++ b/11_ExpressMultiple/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Home'}); +}); + +module.exports = router; diff --git a/11_ExpressMultiple/routes/places.js b/11_ExpressMultiple/routes/places.js new file mode 100644 index 0000000..e84db89 --- /dev/null +++ b/11_ExpressMultiple/routes/places.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET users listing. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Places' }); +}); + +module.exports = router; diff --git a/11_ExpressMultiple/routes/users.js b/11_ExpressMultiple/routes/users.js new file mode 100644 index 0000000..623e430 --- /dev/null +++ b/11_ExpressMultiple/routes/users.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET users listing. */ +router.get('/', function(req, res, next) { + res.send('respond with a resource'); +}); + +module.exports = router; diff --git a/11_ExpressMultiple/views/error.jade b/11_ExpressMultiple/views/error.jade new file mode 100644 index 0000000..51ec12c --- /dev/null +++ b/11_ExpressMultiple/views/error.jade @@ -0,0 +1,6 @@ +extends layout + +block content + h1= message + h2= error.status + pre #{error.stack} diff --git a/11_ExpressMultiple/views/index.jade b/11_ExpressMultiple/views/index.jade new file mode 100644 index 0000000..3d63b9a --- /dev/null +++ b/11_ExpressMultiple/views/index.jade @@ -0,0 +1,5 @@ +extends layout + +block content + h1= title + p Welcome to #{title} diff --git a/11_ExpressMultiple/views/layout.jade b/11_ExpressMultiple/views/layout.jade new file mode 100644 index 0000000..15af079 --- /dev/null +++ b/11_ExpressMultiple/views/layout.jade @@ -0,0 +1,7 @@ +doctype html +html + head + title= title + link(rel='stylesheet', href='/stylesheets/style.css') + body + block content diff --git a/12_AdvancedRESTAPI/app.js b/12_AdvancedRESTAPI/app.js new file mode 100644 index 0000000..37fb28d --- /dev/null +++ b/12_AdvancedRESTAPI/app.js @@ -0,0 +1,141 @@ +#!/usr/bin/env node + +/** + * Module dependencies. + */ + +var http = require('http'); +var express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); + +var routes = require('./routes/index'); +var api = require('./routes/api'); + +var app = express(); + +// uncomment after placing your favicon in /public +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', routes); +app.use('/api', api); + +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// error handlers + +// development error handler +// will print stacktrace +if (app.get('env') === 'development') { + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: err + }); + }); +} + +// production error handler +// no stacktraces leaked to user +app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: {} + }); +}); + +/** + * Get port from environment and store in Express. + */ + +var port = normalizePort(process.env.PORT || '3000'); +app.set('port', port); + +/** + * Create HTTP server. + */ + +var server = http.createServer(app); + +/** + * Listen on provided port, on all network interfaces. + */ + +server.listen(port); +server.on('error', onError); +server.on('listening', onListening); + +/** + * Normalize a port into a number, string, or false. + */ + +function normalizePort(val) { + var port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; +} + +/** + * Event listener for HTTP server "error" event. + */ + +function onError(error) { + if (error.syscall !== 'listen') { + throw error; + } + + var bind = typeof port === 'string' + ? 'Pipe ' + port + : 'Port ' + port; + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } +} + +/** + * Event listener for HTTP server "listening" event. + */ + +function onListening() { + var addr = server.address(); + var bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + console.log('Listening on ' + bind); +} \ No newline at end of file diff --git a/12_AdvancedRESTAPI/package.json b/12_AdvancedRESTAPI/package.json new file mode 100644 index 0000000..6694bbe --- /dev/null +++ b/12_AdvancedRESTAPI/package.json @@ -0,0 +1,17 @@ +{ + "name": "12_AdvancedRESTAPI", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./app.js" + }, + "dependencies": { + "body-parser": "~1.13.2", + "cookie-parser": "~1.3.5", + "debug": "~2.2.0", + "express": "~4.13.1", + "jade": "~1.11.0", + "morgan": "~1.6.1", + "serve-favicon": "~2.3.0" + } +} \ No newline at end of file diff --git a/12_AdvancedRESTAPI/routes/api.js b/12_AdvancedRESTAPI/routes/api.js new file mode 100644 index 0000000..f9b5c61 --- /dev/null +++ b/12_AdvancedRESTAPI/routes/api.js @@ -0,0 +1,88 @@ +var express = require('express'); +var router = express.Router(); + +var dogs = [ + { + "dog_id": "0", + "dog_name": "Ginger" + }, + { + "dog_id": "1", + "dog_name": "Ruby" + }, + { + "dog_id": "2", + "dog_name": "Buddy" + } +]; + +/* GET all dogs */ +router.get('/dogs/', function(req, res, next) { + res.json(dogs); +}); + +/* PUT replace all dogs */ +router.put('/dogs/', function(req, res, next) { + console.log(req.body); + dogs = req.body; + res.json({"STATUS": "200 OK"}); +}); + +/* POST create a new dog */ +router.post('/dogs/', function(req, res, next) { + dogs.push(req.body) + res.json({"STATUS": "200 OK"}); +}); + +/* DELETE delete the entire dog collection */ +router.delete('/dogs/', function(req, res, next) { + dogs = []; + res.json({"STATUS": "200 OK"}); +}); + + +/* GET a specific dog */ +router.get('/dogs/:id', function(req, res, next) { + var i = 0; + var dog = null; + for(i = 0; i != dogs.length; i++){ + if(dogs[i].dog_id == req.params.id){ + dog = dogs[i]; + break; + } + } + dog !== null ? res.json(dog) : res.json({"STATUS": "404 NOT FOUND"}) +}); + +/* PUT replace a specific dog with another dog */ +router.put('/dogs/:id', function(req, res, next) { + var i = 0; + var dog = null; + for(i = 0; i != dogs.length; i++){ + if(dogs[i].dog_id == req.params.id){ + dog = dogs[i]; + break; + } + } + if(dog !== null){ + dog.dog_name = req.body['dog_name'] + res.json({"STATUS": "200 OK"}); + } else { + res.json({"STATUS": "404 NOT FOUND"}); + } +}); + +/* DELETE a specific dog from the collection */ +router.delete('/dogs/:id', function(req, res, next) { + var i = 0; + for(i = 0; i != dogs.length; i++){ + if(dogs[i].dog_id == req.params.id){ + dogs.splice(i, 1); + return res.json({"STATUS": "200 OK"}); + } + } + return res.json({"STATUS": "404 NOT FOUND"}); +}); + + +module.exports = router; diff --git a/12_AdvancedRESTAPI/routes/index.js b/12_AdvancedRESTAPI/routes/index.js new file mode 100644 index 0000000..6e345d7 --- /dev/null +++ b/12_AdvancedRESTAPI/routes/index.js @@ -0,0 +1,8 @@ +var express = require('express'); +var router = express.Router(); + +router.get('/', function(req, res, next) { + res.send('Hello World!'); +}); + +module.exports = router; diff --git a/13_MongoDB/app.js b/13_MongoDB/app.js new file mode 100644 index 0000000..8bf9026 --- /dev/null +++ b/13_MongoDB/app.js @@ -0,0 +1,77 @@ +// import the language driver +var MongoClient = require('mongodb').MongoClient + , assert = require('assert'); +var ObjectID = require('mongodb').ObjectID; + +// Connection URL for local mongodb server +var url = 'mongodb://127.0.0.1:27017/test'; + +// Use connect method to connect to the Server +MongoClient.connect(url, function (err, db) { + //ensure we've connected + assert.equal(null, err); + + var bankData = db.collection('bank_data'); + + bankData.insertOne({ + first_name: "Rami", + last_name: "Sayar", + accounts: [ + { + account_balance: "50000000", + account_type: "Investment", + currency: "USD" + }] + }, function (err, op_result) { + + if (err) { + return console.error(err); + } + + console.log('inserted:'); + console.log(op_result.ops[0]); + + var updatedPerson = op_result.ops[0]; + updatedPerson.accounts[0].account_balance += 100000; + + bankData.updateOne({ _id: updatedPerson._id }, updatedPerson, { w: 1 }, function (err, op_result) { + + if (err) { + return console.error(err); + } + + console.log('sucessfully updated ' + op_result.result.n + ' person document'); + + //retrieve the inserted collection from mongodb + //should be the exact same object we just updated + bankData.findOne({ _id: updatedPerson._id }, function (err, doc) { + + if (err) { + return console.error(err); + } + + console.log('retrieved person: ' + doc.first_name + ' ' + doc.last_name); + console.log('accounts: '); + for (var i in doc.accounts) { + console.log('Type: ' + doc.accounts[i].account_type); + console.log('Balance: ' + doc.accounts[i].account_balance); + } + + //now delete the document we just inserted + + bankData.remove({ _id: updatedPerson._id }, function (err, count) { + + if (err) { + db.close(); + return console.error(err); + } + console.log('sucessfully deleted documents'); + + return db.close(); + }); + }); + }); + return; + }); + return console.log("Connected correctly to server"); +}); diff --git a/13_MongoDB/package.json b/13_MongoDB/package.json new file mode 100644 index 0000000..17c4df0 --- /dev/null +++ b/13_MongoDB/package.json @@ -0,0 +1,7 @@ +{ + "name": "13_MongoDB", + "version": "0.0.0", + "dependencies": { + "mongodb": "^2.0.39" + } +} diff --git a/14_AdvancedJade/.settings/launch.json b/14_AdvancedJade/.settings/launch.json new file mode 100644 index 0000000..3b6aa0a --- /dev/null +++ b/14_AdvancedJade/.settings/launch.json @@ -0,0 +1,40 @@ +{ + "version": "0.1.0", + // List of configurations. Add new configurations or edit existing ones. + // ONLY "node" and "mono" are supported, change "type" to switch. + "configurations": [ + { + // Name of configuration; appears in the launch configuration drop down menu. + "name": "Launch ./bin/www", + // Type of configuration. Possible values: "node", "mono". + "type": "node", + // Workspace relative or absolute path to the program. + "program": "./bin/www", + // Automatically stop program after launch. + "stopOnEntry": false, + // Command line arguments passed to the program. + "args": [], + // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace. + "cwd": ".", + // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. + "runtimeExecutable": null, + // Optional arguments passed to the runtime executable. + "runtimeArgs": [], + // Environment variables passed to the program. + "env": { }, + // Use JavaScript source maps (if they exist). + "sourceMaps": false, + // If JavaScript source maps are enabled, the generated code is expected in this directory. + "outDir": null + }, + { + "name": "Attach", + "type": "node", + // TCP/IP address. Default is "localhost". + "address": "localhost", + // Port to attach to. + "port": 5858, + "sourceMaps": false + } + ] +} diff --git a/14_AdvancedJade/app.js b/14_AdvancedJade/app.js new file mode 100644 index 0000000..8bb0172 --- /dev/null +++ b/14_AdvancedJade/app.js @@ -0,0 +1,61 @@ +var express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); + +var routes = require('./routes/index'); +var users = require('./routes/users'); +var places = require('./routes/places'); + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'jade'); + +// uncomment after placing your favicon in /public +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', routes); +app.use('/users', users); +app.use('/places', places); +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// error handlers + +// development error handler +// will print stacktrace +if (app.get('env') === 'development') { + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: err + }); + }); +} + +// production error handler +// no stacktraces leaked to user +app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: {} + }); +}); + + +module.exports = app; diff --git a/14_AdvancedJade/package.json b/14_AdvancedJade/package.json new file mode 100644 index 0000000..1a67384 --- /dev/null +++ b/14_AdvancedJade/package.json @@ -0,0 +1,17 @@ +{ + "name": "11_ExpressMultipleRoutes", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "body-parser": "~1.13.2", + "cookie-parser": "~1.3.5", + "debug": "~2.2.0", + "express": "~4.13.1", + "jade": "~1.11.0", + "morgan": "~1.6.1", + "serve-favicon": "~2.3.0" + } +} \ No newline at end of file diff --git a/14_AdvancedJade/public/stylesheets/style.css b/14_AdvancedJade/public/stylesheets/style.css new file mode 100644 index 0000000..4f3025f --- /dev/null +++ b/14_AdvancedJade/public/stylesheets/style.css @@ -0,0 +1,9 @@ +body { + padding: 50px; + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; +} + +a { + color: #00B7FF; +} + diff --git a/14_AdvancedJade/routes/index.js b/14_AdvancedJade/routes/index.js new file mode 100644 index 0000000..ecca96a --- /dev/null +++ b/14_AdvancedJade/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Express' }); +}); + +module.exports = router; diff --git a/14_AdvancedJade/routes/places.js b/14_AdvancedJade/routes/places.js new file mode 100644 index 0000000..edf4f57 --- /dev/null +++ b/14_AdvancedJade/routes/places.js @@ -0,0 +1,12 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('places', { title: 'Places I Plan on Visiting',hasPlaces:true, + places:{1:{name:"Japan",url:"http://en.wikipedia.org/wiki/Japan"}, + 2:{name:"Scotland",url:"http://en.wikipedia.org/wiki/Scotland"}, + 3:{name:"Brazil",url:"http://en.wikipedia.org/wiki/Brazil"}}}); +}); + +module.exports = router; diff --git a/14_AdvancedJade/routes/users.js b/14_AdvancedJade/routes/users.js new file mode 100644 index 0000000..623e430 --- /dev/null +++ b/14_AdvancedJade/routes/users.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET users listing. */ +router.get('/', function(req, res, next) { + res.send('respond with a resource'); +}); + +module.exports = router; diff --git a/14_AdvancedJade/views/error.jade b/14_AdvancedJade/views/error.jade new file mode 100644 index 0000000..51ec12c --- /dev/null +++ b/14_AdvancedJade/views/error.jade @@ -0,0 +1,6 @@ +extends layout + +block content + h1= message + h2= error.status + pre #{error.stack} diff --git a/14_AdvancedJade/views/index.jade b/14_AdvancedJade/views/index.jade new file mode 100644 index 0000000..01bc729 --- /dev/null +++ b/14_AdvancedJade/views/index.jade @@ -0,0 +1,6 @@ +extends layout + +block content + h1= title + p Welcome to #{title} + a.stacey(href="/places") Places diff --git a/14_AdvancedJade/views/layout.jade b/14_AdvancedJade/views/layout.jade new file mode 100644 index 0000000..6eda78d --- /dev/null +++ b/14_AdvancedJade/views/layout.jade @@ -0,0 +1,10 @@ +doctype html +html + head + title= title + link(rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css') + link(rel='stylesheet', href='/stylesheets/style.css') + script(src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js') + + body + block content diff --git a/14_AdvancedJade/views/places.jade b/14_AdvancedJade/views/places.jade new file mode 100644 index 0000000..b0d2765 --- /dev/null +++ b/14_AdvancedJade/views/places.jade @@ -0,0 +1,22 @@ +extends layout + +block content + h1= title + h2#maintitle Where shall we go today? + p + | If I could, I would spend all my time on + a(href="http://expedia.com") Travel Sites + | and book flights on someone else's dime. + + div + ul + each val, index in places + li + a(href=val.url)= val.name + + div + if hasPlaces + a(href="/") Home + + + diff --git a/15_WebJobSimple/package.json b/15_WebJobSimple/package.json new file mode 100644 index 0000000..3a229ed --- /dev/null +++ b/15_WebJobSimple/package.json @@ -0,0 +1,17 @@ +{ + "name": "webjobsimple", + "version": "1.0.0", + "description": "Example simple web job that shows it being called ", + "main": "run.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "Node", + "Azure", + "Web", + "Job" + ], + "author": "Stacey Mulcahy", + "license": "ISC" +} diff --git a/15_WebJobSimple/run.js b/15_WebJobSimple/run.js new file mode 100644 index 0000000..d4b27b1 --- /dev/null +++ b/15_WebJobSimple/run.js @@ -0,0 +1,4 @@ + +setInterval(function(){ + console.log("Repeatedly calling this function"); +},5000); \ No newline at end of file diff --git a/16_WebJobStorage/package.json b/16_WebJobStorage/package.json new file mode 100644 index 0000000..2ca55c5 --- /dev/null +++ b/16_WebJobStorage/package.json @@ -0,0 +1,16 @@ +{ + "name": "webjobstorage", + "version": "1.0.0", + "description": "Example demo for using Azure blob storage with node in a web job", + "main": "run.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "azure-storage": "^0.4.5", + "instagram-node": "^0.5.7", + "request": "^2.60.0" + } +} diff --git a/16_WebJobStorage/run.js b/16_WebJobStorage/run.js new file mode 100644 index 0000000..6279402 --- /dev/null +++ b/16_WebJobStorage/run.js @@ -0,0 +1,74 @@ + + +var azure = require('azure-storage'); +var fs = require('fs'); +var https = require('https'); +var request = require('request'); + +console.log(process.env.BLOB_NAME); + +var blobService = azure.createBlobService(process.env.BLOB_NAME, process.env.BLOB_KEY); + + +var ig = require('instagram-node').instagram(); +ig.use({ access_token: process.env.INSTA_ACCESS_TOKEN }); + +ig.use({ client_id: process.env.INSTA_CLIENT_ID, client_secret: process.env.INSTA_CLIENT_SECRET }); + + + +ig.user_media_recent(process.env.INSTA_USER, function (err, medias, pagination, remaining, limit, res) { + + var len = medias.length; + var counter = 0; + + next(); + + function next() { + var item = medias[counter]; + var file = fs.createWriteStream("placeholder.jpg"); + var imageURL = item.images.standard_resolution.url; + var created = item.created_time; + console.log(imageURL); + var request = https.get(imageURL, function (response) { + + response.pipe(file); + file.on('finish', function () { + blobService.createBlockBlobFromLocalFile(process.env.BLOB_CONTAINER, created, 'placeholder.jpg', function (error, result, response) { + if (!error) { + // file uploaded + console.log("Successful call"); + counter++; + if (counter < len) { + next(); + } else { + console.log("This process is complete"); + process.exit(); + } + } else { + console.log("There is a problem") + } + }); + }); + + }); + } + + +}); + + + + + + + + + + + + + + + + diff --git a/Presentations for Visual Studio Code MVA/01.Intro-to-node.pptx b/Presentations for Visual Studio Code MVA/01.Intro-to-node.pptx new file mode 100644 index 0000000..dac1e9e Binary files /dev/null and b/Presentations for Visual Studio Code MVA/01.Intro-to-node.pptx differ diff --git a/Presentations for Visual Studio Code MVA/02.Express.pptx b/Presentations for Visual Studio Code MVA/02.Express.pptx new file mode 100644 index 0000000..e3b59a2 Binary files /dev/null and b/Presentations for Visual Studio Code MVA/02.Express.pptx differ diff --git a/Presentations for Visual Studio Code MVA/03.Express-and-databases.pptx b/Presentations for Visual Studio Code MVA/03.Express-and-databases.pptx new file mode 100644 index 0000000..863314e Binary files /dev/null and b/Presentations for Visual Studio Code MVA/03.Express-and-databases.pptx differ diff --git a/Presentations for Visual Studio Code MVA/04.Building-a-frontend-for-your-express-web-apps.pptx b/Presentations for Visual Studio Code MVA/04.Building-a-frontend-for-your-express-web-apps.pptx new file mode 100644 index 0000000..0c2e8bd Binary files /dev/null and b/Presentations for Visual Studio Code MVA/04.Building-a-frontend-for-your-express-web-apps.pptx differ diff --git a/Presentations for Visual Studio Code MVA/05.Debugging-and-deploying-nodejs.pptx b/Presentations for Visual Studio Code MVA/05.Debugging-and-deploying-nodejs.pptx new file mode 100644 index 0000000..d3e6cf2 Binary files /dev/null and b/Presentations for Visual Studio Code MVA/05.Debugging-and-deploying-nodejs.pptx differ diff --git a/Presentations for Visual Studio Code MVA/06.WebJobsNode.pptx b/Presentations for Visual Studio Code MVA/06.WebJobsNode.pptx new file mode 100644 index 0000000..3ac27a1 Binary files /dev/null and b/Presentations for Visual Studio Code MVA/06.WebJobsNode.pptx differ diff --git a/README.md b/README.md index 2e0c8a7..e4f9e13 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,16 @@ -# Project Repository for Building Apps with Node.js Microsoft Virtual Academy +# Repository for 'Building Apps with Node.js' & 'Using Node.js with Visual Studio Code' Microsoft Virtual Academy Videos -This is the project repository containing the source code for all the demos in the "Building Apps with Node.js" Micorosft Virtual Academy course. +This is the repository containing the source code for all the demos and the PowerPoint presentations in the "Building Apps with Node.js" & "Using Node.js with Visual Studio Code" Microsoft Virtual Academy courses. These courses were developed by [Rami Sayar](https://twitter.com/ramisayar) && [Stacey Mulcahy](https://twitter.com/bitchwhocodes), both technical evangelists at Microsoft. -## Useful Resources +In [Building Apps with Node.js](https://www.microsoftvirtualacademy.com/en-US/training-courses/building-apps-with-node-js-jump-start-8422), we teach how to develop web applications with Node.js and touch on topics like how to incorporate two-way communication into applications. In this course, you can see step-by-step demos and get practical tips and detailed explanations. By the end of the day, you know how to set up Node.js on your Windows machine, develop a web front end with Express, deploy an Express app to Azure, use Socket.IO to add a real-time layer, and bring it all together. + +In [Using Node.js with Visual Studio Code](http://www.microsoftvirtualacademy.com/liveevents/using-node-js-with-visual-studio-code), we showcase how to write code with Visual Studio Code? Visual Studio Code is far more than a text editor, it works cross platform, looks great, has a ton of cool features, and is becoming increasingly popular! In this course, we walk through the tool's features, learn how to customize them, and explore the key commands. See how to create a basic REST API using Node.js with Express, connect your web app to a database, and learn how to debug Node.js apps using Visual Studio Code. Plus, see how to deploy your sites to Microsoft Azure, and create, test, and schedule Azure Web Jobs. + +## Useful Articles * [A chatroom for all! Part 1 - Introduction to Node.js](http://blogs.msdn.com/b/cdndevs/archive/2014/09/04/node-js-tutorial-series-a-chatroom-for-all-part-1-introduction-to-node.aspx) * [A chatroom for all! Part 2 - Welcome to Express with Node.js and Azure](http://blogs.msdn.com/b/cdndevs/archive/2014/09/11/a-chatroom-for-all-part-2-welcome-to-express-with-node-js-and-azure.aspx) * [A chatroom for all! Part 3 - Building a Backend with Node, Mongo and Socket.IO](http://blogs.msdn.com/b/cdndevs/archive/2014/09/19/a-chatroom-for-all-part-3-building-a-backend-with-node-mongo-and-socket-io.aspx) * [A chatroom for all! Part 4 - Building a Chatroom UI with Bootstrap](http://blogs.msdn.com/b/cdndevs/archive/2014/09/25/a-chatroom-for-all-part-4-building-a-chatroom-ui-with-bootstrap-node-js.aspx) * [A chatroom for all! Part 5 - Connecting the Chatroom with WebSockets](http://blogs.msdn.com/b/cdndevs/archive/2014/10/03/a-chatroom-for-all-part-5-connecting-the-chatroom-with-websockets.aspx) -* [A chatroom for all! Part 6 - The Finale and Debugging Remote Node Apps!](http://blogs.msdn.com/b/cdndevs/archive/2014/10/10/a-chatroom-for-all-part-6-the-finale-and-debugging-remote-node-apps.aspx) \ No newline at end of file +* [A chatroom for all! Part 6 - The Finale and Debugging Remote Node Apps!](http://blogs.msdn.com/b/cdndevs/archive/2014/10/10/a-chatroom-for-all-part-6-the-finale-and-debugging-remote-node-apps.aspx)