diff --git a/lectureExamples/demoNodeApp/hello.js b/lectureExamples/demoNodeApp/hello.js new file mode 100644 index 0000000000000000000000000000000000000000..309af59b683df095e4dff221fb4fdc70e2872d20 --- /dev/null +++ b/lectureExamples/demoNodeApp/hello.js @@ -0,0 +1 @@ +console.log('hi') \ No newline at end of file diff --git a/lectureExamples/demoNodeApp/package.json b/lectureExamples/demoNodeApp/package.json new file mode 100644 index 0000000000000000000000000000000000000000..7a86a3acdae11d7963134258b0dae63a6c1278b2 --- /dev/null +++ b/lectureExamples/demoNodeApp/package.json @@ -0,0 +1,11 @@ +{ + "name": "demonodeapp", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/lectureExamples/driver.js b/lectureExamples/driver.js new file mode 100644 index 0000000000000000000000000000000000000000..e13dc9039a5daa8405909eeee55b8bb30fd4286e --- /dev/null +++ b/lectureExamples/driver.js @@ -0,0 +1,4 @@ +let sharedAdd = require('./functions').myAdd + + +console.log(sharedAdd(1,4)) \ No newline at end of file diff --git a/lectureExamples/functions.js b/lectureExamples/functions.js new file mode 100644 index 0000000000000000000000000000000000000000..9ddc9abcf941fd7a90c42d89952a70474cfabbc6 --- /dev/null +++ b/lectureExamples/functions.js @@ -0,0 +1,10 @@ +function myAdd(num1, num2) { + return num1 + num2 +} + +function mySubtract(num1, num2) { + return num1 - num2 +} + +module.exports.myAdd = myAdd +module.exports.mySubtract = mySubtract \ No newline at end of file diff --git a/lectureExamples/newFetch.html b/lectureExamples/newFetch.html new file mode 100644 index 0000000000000000000000000000000000000000..aa9e0905734fe8f1035f1d933d9a14e4521e6da3 --- /dev/null +++ b/lectureExamples/newFetch.html @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <title>Fetch and Promises</title> + <meta charset="utf-8" /> +</head> + +<body> + <script> + + let url = "https://jsonplaceholder.typicode.com/todos/1"; // Notice the 1 at the end + + let data = { + "userId": 1, + "id": 1, + "title": "delectus aut autem", + "completed": false + } + console.log(data) + console.log(JSON.stringify(data)) + // This is going to mock what happens when we call the real Fetch API + + function newFetch(data2) { + return new Promise((resolve, reject) => { + setTimeout(() => { + if (data2 === null) { + reject("Object is null") + } + resolve(data2) + }, 3000) + }) + } + + let result = newFetch(data) + + + newFetch(data) + .then(result => { + console.log('printing from newFetch') + console.log(result) + }) + .catch(err => console.error(err)) + + </script> +</body> + +</html> \ No newline at end of file