├── .gitignore ├── Ch00-TableOfContents.ipynb ├── Ch01-JavaScriptIntro.ipynb ├── Ch02-Output-DataTypes-Variables.ipynb ├── Ch03-Built-inFunctions-NPM.ipynb ├── Ch04-1-UserDefinedFunctions.ipynb ├── Ch04-2-AsynchronousProgramming.ipynb ├── Ch05-Numbers-And-Math.ipynb ├── Ch06-Conditionals.ipynb ├── Ch07-Modules.ipynb ├── Ch08-UnitTesting.ipynb ├── Ch09-Loops.ipynb ├── Ch10-Strings.ipynb ├── Ch11-Arrays.ipynb ├── Ch12-Object-Dict.ipynb ├── Ch13-Files.ipynb ├── Ch14-JSON.ipynb ├── Ch15-Errors-And-Exceptions.ipynb ├── Ch16-OOP-Class.ipynb ├── Ch17-RegularExpression.ipynb ├── Ch18-React.ipynb ├── Ch19-Node.js-Server.ipynb ├── Ch20-Express-React.ipynb ├── Ch21-MongoDB.ipynb ├── Ch22-Mongo-Express-React-Node.ipynb ├── Ch23-Next-React-Fullstack.ipynb ├── Ch25-Functional-Programming.ipynb ├── ClientSideJS ├── cookie.html ├── formElementsDemo.html ├── game.js ├── guessNumber.html ├── localStorageDemo copy.html ├── localStorageDemo.html ├── react.html ├── selectorDemo.html └── style.css ├── ExpressDemos ├── hello-world │ ├── .babelrc │ ├── hello-express.js │ ├── hello-router.js │ ├── package-lock.json │ └── package.json └── homepage │ ├── LICENSE │ ├── app.js │ ├── bin │ └── www │ ├── package-lock.json │ ├── package.json │ ├── public │ ├── assets │ │ ├── EBC.JPG │ │ ├── basnet_icon32.ico │ │ ├── bg-footer.jpg │ │ ├── bg-header.jpg │ │ ├── cmu-logo.png │ │ ├── contact.jpeg │ │ ├── honda.jpg │ │ ├── profile.png │ │ ├── profile1.jpg │ │ ├── research.jpg │ │ ├── resources.jpg │ │ ├── style.css │ │ └── teaching.png │ └── stylesheets │ │ └── style.css │ ├── routes │ └── home.js │ └── views │ ├── contact.html │ ├── index.html │ ├── research.html │ ├── resources.html │ └── teaching.html ├── ExpressMongoDemos ├── pug │ └── gradebook-v1 │ │ ├── .env.local │ │ ├── app.js │ │ ├── bin │ │ └── www │ │ ├── models │ │ └── user.js │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── public │ │ ├── javascripts │ │ │ └── jquery.min.js │ │ └── stylesheets │ │ │ └── style.css │ │ ├── routes │ │ ├── index.js │ │ └── users.js │ │ └── views │ │ ├── dashboard.pug │ │ ├── error.pug │ │ ├── index.pug │ │ ├── layout.pug │ │ ├── login.pug │ │ ├── profile.pug │ │ ├── signup.pug │ │ └── users.js └── react │ ├── authenticate_demo │ └── client │ │ ├── .gitignore │ │ ├── README.md │ │ ├── package.json │ │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ │ ├── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ ├── reportWebVitals.js │ │ └── setupTests.js │ │ └── yarn.lock │ ├── gradebook-v1 │ ├── .babelrc │ ├── app.js │ ├── bin │ │ └── www │ ├── models │ │ └── user.js │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── javascripts │ │ │ └── jquery.min.js │ │ └── stylesheets │ │ │ └── style.css │ ├── routes │ │ ├── index.js │ │ └── users.js │ └── views │ │ ├── components │ │ ├── header.jsx │ │ └── message.jsx │ │ ├── dashboard.jsx │ │ ├── error.jsx │ │ ├── index.jsx │ │ ├── layout.jsx │ │ ├── login.jsx │ │ ├── profile.jsx │ │ ├── signup.jsx │ │ └── users.js │ └── gradebook-v2 │ ├── .babelrc │ ├── .gitignore │ ├── README.md │ ├── app.js │ ├── bin │ └── www │ ├── models │ ├── course.js │ └── user.js │ ├── package-lock.json │ ├── package.json │ ├── public │ ├── javascripts │ │ └── jquery.min.js │ └── stylesheets │ │ └── style.css │ ├── routes │ ├── router.js │ └── users.js │ └── views │ ├── components │ ├── course.jsx │ ├── header.jsx │ └── message.jsx │ ├── courses.jsx │ ├── dashboard.jsx │ ├── error.jsx │ ├── index.jsx │ ├── layout.jsx │ ├── login.jsx │ ├── profile.jsx │ ├── register.jsx │ └── users.js ├── ExpressReactDemos ├── dynamic │ ├── .babelrc │ ├── .gitignore │ ├── app.js │ ├── package-lock.json │ ├── package.json │ ├── public │ │ └── favicon.ico │ ├── readme.md │ └── views │ │ ├── Html.js │ │ ├── TodoApp.js │ │ └── main.js ├── express-API-react-client │ ├── api │ │ ├── app.js │ │ ├── bin │ │ │ └── www │ │ ├── data │ │ │ └── courses.json │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── public │ │ │ └── stylesheets │ │ │ │ └── style.css │ │ ├── routes │ │ │ ├── courses.js │ │ │ ├── index.js │ │ │ ├── testAPI.js │ │ │ └── users.js │ │ └── views │ │ │ ├── error.jade │ │ │ ├── index.jade │ │ │ └── layout.jade │ └── client │ │ ├── .gitignore │ │ ├── README.md │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ │ └── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── components │ │ └── Courses.jsx │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ ├── reportWebVitals.js │ │ └── setupTests.js ├── homepage │ ├── .babelrc │ ├── app.js │ ├── bin │ │ └── www │ ├── data │ │ ├── background.json │ │ ├── courses.json │ │ └── publications.json │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── assets │ │ │ ├── EBC.JPG │ │ │ ├── bg-footer.jpg │ │ │ ├── bg-header.jpg │ │ │ ├── cmu-logo.png │ │ │ ├── contact.jpeg │ │ │ ├── favicon_32.ico │ │ │ ├── honda.jpg │ │ │ ├── profile.png │ │ │ ├── research.jpg │ │ │ ├── resources.jpg │ │ │ ├── style.css │ │ │ └── teaching.png │ │ └── stylesheets │ │ │ └── style.css │ ├── routes │ │ └── router.js │ └── views │ │ ├── contact.jsx │ │ ├── includes │ │ ├── background.js │ │ ├── banner.js │ │ ├── courses.js │ │ ├── footer.js │ │ ├── navigation.js │ │ ├── publication.js │ │ └── schedule.js │ │ ├── index.jsx │ │ ├── layout.jsx │ │ ├── research.jsx │ │ ├── resources.jsx │ │ └── teaching.jsx └── simple │ ├── app.js │ ├── data │ └── users.json │ ├── package-lock.json │ ├── package.json │ ├── public │ └── stylesheets │ │ └── style.css │ ├── routes │ ├── index.js │ └── user.js │ └── views │ ├── index.jsx │ ├── layout.jsx │ └── users.jsx ├── JSDemos ├── async-input.js ├── async-input.mjs ├── async-input1.js ├── async-input2.js ├── circle.js ├── cold │ ├── 1.ans │ ├── 1.in │ ├── 2.ans │ ├── 2.in │ └── cold.js ├── commandLineArgs.js ├── hello.js ├── index.html ├── input.txt ├── library │ ├── my_math.js │ └── my_math.mjs ├── moduleDemo.js ├── moduleDemo.mjs ├── myScript.mjs ├── oop_static.js ├── output1.html ├── output2.html ├── output3.html ├── output4.html ├── package-lock.json ├── package.json ├── packages_demo │ └── chalk-demo.mjs ├── sync-input.js └── unittesting │ ├── demo1.js │ ├── demo2.js │ ├── func_sub.test.js │ ├── functions.js │ ├── functions_add.test.js │ ├── package-lock.json │ └── package.json ├── LICENSE ├── NextJSDemos └── mflix │ ├── .gitignore │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── pages │ ├── api │ │ └── movies.js │ ├── index.js │ ├── movies.js │ └── top.js │ ├── public │ ├── favicon.ico │ └── vercel.svg │ └── util │ └── mongodb.js ├── NodeDemos ├── datetime.js ├── hello-world.js ├── index.html └── index.js ├── README.md ├── ReactDemos ├── LICENSE ├── README.md ├── homepage-v0 │ ├── assets │ │ ├── EBC.JPG │ │ ├── basnet_icon32.ico │ │ ├── bg-footer.jpg │ │ ├── bg-header.jpg │ │ ├── cmu-logo.png │ │ ├── contact.jpeg │ │ ├── honda.jpg │ │ ├── profile.png │ │ ├── profile1.jpg │ │ ├── research.jpg │ │ ├── resources.jpg │ │ ├── style.css │ │ └── teaching.png │ ├── contact.html │ ├── index.html │ ├── research.html │ ├── resources.html │ └── teaching.html ├── homepage-v1 │ ├── LICENSE │ ├── README.md │ ├── app.js │ ├── bin │ │ └── www │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── assets │ │ │ ├── EBC.JPG │ │ │ ├── basnet_icon32.ico │ │ │ ├── bg-footer.jpg │ │ │ ├── bg-header.jpg │ │ │ ├── cmu-logo.png │ │ │ ├── contact.jpeg │ │ │ ├── honda.jpg │ │ │ ├── profile.png │ │ │ ├── profile1.jpg │ │ │ ├── research.jpg │ │ │ ├── resources.jpg │ │ │ ├── style.css │ │ │ └── teaching.png │ │ ├── stylesheets │ │ │ └── style.css │ │ └── ui │ │ │ ├── footer.js │ │ │ ├── header.js │ │ │ ├── navbar.js │ │ │ └── publication.js │ ├── routes │ │ └── home.js │ └── views │ │ ├── contact.html │ │ ├── index.html │ │ ├── research.html │ │ ├── resources.html │ │ └── teaching.html ├── homepage-v2 │ ├── .gitignore │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── assets │ │ │ ├── EBC.JPG │ │ │ ├── basnet_icon32.ico │ │ │ ├── bg-footer.jpg │ │ │ ├── bg-header.jpg │ │ │ ├── cmu-logo.png │ │ │ ├── contact.jpeg │ │ │ ├── honda.jpg │ │ │ ├── profile.png │ │ │ ├── research.jpg │ │ │ ├── resources.jpg │ │ │ ├── style.css │ │ │ └── teaching.png │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ └── robots.txt │ └── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── components │ │ ├── banner.js │ │ ├── data │ │ │ └── publications.json │ │ ├── footer.js │ │ ├── home.js │ │ ├── navbar.js │ │ ├── page-not-found.js │ │ ├── publication.js │ │ └── teaching.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ ├── reportWebVitals.js │ │ └── setupTests.js ├── react-jsx-intro │ ├── 01-js-hello.html │ ├── 02-js-funct-event.html │ ├── 03-react-hello.html │ ├── 04-react-components.html │ ├── 05-jsx-expressions.html │ ├── 06-jsx-attributes-children.html │ ├── 07-jsx-events-functions.html │ ├── 08-jsx-render-update.html │ ├── 09-jsx-function-component.html │ ├── 10-jsx-conditional-rendering.html │ ├── 11-jsx-class-component.html │ ├── 12-jsx-state-lifecycle.html │ ├── 13-jsx-events-methods.html │ ├── 14-jsx-events-methods-1.html │ ├── 15-jsx-form.html │ ├── 16-jsx-library-integration.html │ └── 17-jax-app.html └── route-testing-demo │ ├── .gitignore │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt │ └── src │ ├── App.css │ ├── App.js │ ├── components │ ├── dashboard.js │ ├── home.js │ ├── login_form.js │ └── menu.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ ├── setupTests.js │ └── tests │ ├── App.test.js │ ├── Home.test.js │ └── LoginForm.test.js ├── package-lock.json ├── package.json └── resources ├── MongoDBCompass.png ├── Postman.png ├── Robo3T.png ├── beachball.jpg ├── event_loop.jpg ├── inheritance.png ├── promises.png ├── react-testing.png └── repo-setting-react.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # others 64 | .ipynb_checkpoints/ 65 | *.DS_Store 66 | .vs_code/ 67 | -------------------------------------------------------------------------------- /ClientSideJS/cookie.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 38 | 39 |

Playing with Cookies

40 |

Doesn't work!!

41 | Cookie Name: 42 | Value 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ClientSideJS/game.js: -------------------------------------------------------------------------------- 1 | function playgame() { 2 | var number = $("#number").val(); 3 | //alert(hidden); 4 | //alert(number); 5 | if (isNaN(number) || number=='' || number<1 || number > 20) { 6 | $("#hint").text("Enter a valid number between 1 and 20"); 7 | return; 8 | } 9 | tries++; 10 | if (tries > maxTries) { 11 | $("#hint").text(`Sorry, you lose! The number was ${hidden}`); 12 | $("#reset").show(); 13 | $("#btnSubmit").attr("disabled", true); 14 | return; 15 | } 16 | 17 | if (number > hidden) { 18 | $("#hint").text("Your number is too large!"); 19 | } 20 | else if(number < hidden) { 21 | $("#hint").text("Your number is too small!"); 22 | } 23 | else { 24 | $("#hint").text(`Congrats! You gessed my number in ${tries} tries!`); 25 | $("#reset").show(); 26 | } 27 | } -------------------------------------------------------------------------------- /ClientSideJS/guessNumber.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 31 | 32 | 33 | 34 | 35 | 36 |

Guess The Number Game

37 |
38 |

Enter a number between 1 and 20

39 |

Number of tries left:

40 |
41 | Number: 42 | 43 |

44 | 45 |
46 |
47 | 48 | -------------------------------------------------------------------------------- /ClientSideJS/localStorageDemo copy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 38 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /ClientSideJS/localStorageDemo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 37 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ClientSideJS/react.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 |
10 |
11 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /ClientSideJS/selectorDemo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 24 | 40 | 41 | 42 | 43 | 44 |

A Simple Calculator

45 |
46 |
47 |
48 | 49 |

50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /ClientSideJS/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #a3d3f7; 3 | } 4 | 5 | h1 { 6 | text-align: center; 7 | } 8 | 9 | #counter { 10 | color: red; 11 | font-weight: bolder; 12 | } -------------------------------------------------------------------------------- /ExpressDemos/hello-world/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ] 5 | } -------------------------------------------------------------------------------- /ExpressDemos/hello-world/hello-express.js: -------------------------------------------------------------------------------- 1 | //let express = require("express"); 2 | import express from 'express'; 3 | const app = express(); 4 | const port = 9999; 5 | 6 | app.get("/", (req, res) => { 7 | res.send("Hello Express!"); 8 | }); 9 | 10 | let server = app.listen(port, () => { 11 | let host = server.address().address; 12 | let port = server.address().port; 13 | console.log(`Example app listening at http://${host}:${port}`); 14 | }); 15 | -------------------------------------------------------------------------------- /ExpressDemos/hello-world/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "expressdemo", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "nodemon --exec babel-node hello-express.js" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "description": "", 12 | "dependencies": { 13 | "express": "^4.17.1", 14 | "nodemon": "^2.0.7" 15 | }, 16 | "devDependencies": { 17 | "@babel/core": "^7.13.10", 18 | "@babel/node": "^7.13.12", 19 | "@babel/preset-env": "^7.13.12" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ExpressDemos/homepage/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ram Basnet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ExpressDemos/homepage/app.js: -------------------------------------------------------------------------------- 1 | var createError = require("http-errors") 2 | var express = require("express") 3 | var path = require("path") 4 | var cookieParser = require("cookie-parser") 5 | var logger = require("morgan") 6 | 7 | var homeRouter = require("./routes/home") 8 | 9 | var app = express() 10 | 11 | // view engine setup 12 | app.set("views", path.join(__dirname, "views")) 13 | app.set("view engine", "pug") 14 | 15 | app.use(logger("dev")) 16 | app.use(express.json()) 17 | app.use(express.urlencoded({ extended: false })) 18 | app.use(cookieParser()) 19 | 20 | app.use(express.static(path.join(__dirname, "public"))) 21 | app.use("/home", express.static(path.join(__dirname, "public"))) 22 | 23 | // add your routers 24 | app.use("/", homeRouter) 25 | 26 | // catch 404 and forward to error handler 27 | app.use(function(req, res, next) { 28 | next(createError(404)) 29 | }) 30 | 31 | // error handler 32 | app.use(function(err, req, res, next) { 33 | // set locals, only providing error in development 34 | res.locals.message = err.message 35 | res.locals.error = req.app.get("env") === "development" ? err : {} 36 | 37 | // render the error page 38 | res.status(err.status || 500) 39 | res.render("error") 40 | }) 41 | 42 | module.exports = app 43 | -------------------------------------------------------------------------------- /ExpressDemos/homepage/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('expressdemo:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' 62 | ? 'Pipe ' + port 63 | : 'Port ' + port; 64 | 65 | // handle specific listen errors with friendly messages 66 | switch (error.code) { 67 | case 'EACCES': 68 | console.error(bind + ' requires elevated privileges'); 69 | process.exit(1); 70 | break; 71 | case 'EADDRINUSE': 72 | console.error(bind + ' is already in use'); 73 | process.exit(1); 74 | break; 75 | default: 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Event listener for HTTP server "listening" event. 82 | */ 83 | 84 | function onListening() { 85 | var addr = server.address(); 86 | var bind = typeof addr === 'string' 87 | ? 'pipe ' + addr 88 | : 'port ' + addr.port; 89 | debug('Listening on ' + bind); 90 | } 91 | -------------------------------------------------------------------------------- /ExpressDemos/homepage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "expressdemo", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "cookie-parser": "~1.4.3", 10 | "debug": "~2.6.9", 11 | "express": "~4.16.0", 12 | "http-errors": "~1.6.2", 13 | "morgan": "~1.9.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/EBC.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/EBC.JPG -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/basnet_icon32.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/basnet_icon32.ico -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/bg-footer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/bg-footer.jpg -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/bg-header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/bg-header.jpg -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/cmu-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/cmu-logo.png -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/contact.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/contact.jpeg -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/honda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/honda.jpg -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/profile.png -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/profile1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/profile1.jpg -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/research.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/research.jpg -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/resources.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/resources.jpg -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/style.css: -------------------------------------------------------------------------------- 1 | #header { 2 | background-image:url(bg-header.jpg); 3 | background-repeat: no-repeat; 4 | background-size: cover; 5 | color: white; 6 | text-shadow: 2px 2px rgb(4, 4, 109); 7 | background-color: maroon; 8 | border-radius: 0px; 9 | } 10 | 11 | #footer { 12 | clear:both; 13 | height:100px; 14 | background:url(bg-footer.jpg); 15 | background-repeat: repeat-x; 16 | background-color: rgb(103, 141, 15); 17 | height: 100px; 18 | } 19 | 20 | .officehour 21 | { 22 | background:#D0F5A9; 23 | font-weight: bolder; 24 | text-align: center; 25 | font-size: 14px; 26 | } 27 | 28 | .schedule 29 | { 30 | background:#FAFFFA; 31 | text-align: center; 32 | font-size: 14px; 33 | } 34 | 35 | #footer { 36 | margin-bottom:0; 37 | padding-top:45px; 38 | } 39 | 40 | #currentPage 41 | { 42 | color: white; 43 | } -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/assets/teaching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressDemos/homepage/public/assets/teaching.png -------------------------------------------------------------------------------- /ExpressDemos/homepage/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /ExpressDemos/homepage/routes/home.js: -------------------------------------------------------------------------------- 1 | var express = require("express") 2 | var router = express.Router() 3 | var path = require("path") 4 | 5 | router.get("/", function(req, res, next) { 6 | //res.send(path.join(__dirname + "/../views/index.html")) 7 | res.sendFile(path.join(__dirname + "/../views/index.html")) 8 | }) 9 | 10 | router.get("/index.html", function(req, res, next) { 11 | //res.send(path.join(__dirname + "/../views/index.html")) 12 | res.sendFile(path.join(__dirname + "/../views/index.html")) 13 | }) 14 | 15 | router.get("/teaching.html", function(req, res, next) { 16 | res.sendFile(path.join(__dirname + "/../views/teaching.html")) 17 | }) 18 | 19 | router.get("/research.html", function(req, res, next) { 20 | res.sendFile(path.join(__dirname + "/../views/research.html")) 21 | }) 22 | 23 | router.get("/resources.html", function(req, res, next) { 24 | res.sendFile(path.join(__dirname + "/../views/resources.html")) 25 | }) 26 | 27 | router.get("/contact.html", function(req, res, next) { 28 | res.sendFile(path.join(__dirname + "/../views/contact.html")) 29 | }) 30 | 31 | module.exports = router 32 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/.env.local: -------------------------------------------------------------------------------- 1 | MONGODB_URI=mongodb+srv://:@cluster0.qdxhi.mongodb.net/gradebook?retryWrites=true&w=majority -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/models/user.js: -------------------------------------------------------------------------------- 1 | var mongoose = require("mongoose") 2 | 3 | var Schema = mongoose.Schema 4 | 5 | var UserSchema = new Schema({ 6 | email: { type: String, required: true, max: 100 }, 7 | password: { type: String, required: true, max: 100 }, 8 | firstName: { type: String, required: false, max: 30 }, 9 | lastName: { type: String, required: false, max: 30 } 10 | }) 11 | 12 | // Export model 13 | module.exports = mongoose.model("User", UserSchema, "users") 14 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gradebook", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "nodemon ./bin/www" 7 | }, 8 | "dependencies": { 9 | "cookie-parser": "~1.4.3", 10 | "debug": "~2.6.9", 11 | "event-stream": "^3.3.4", 12 | "express": "~4.16.0", 13 | "express-session": "^1.15.6", 14 | "express-validator": "^5.3.0", 15 | "http-errors": "~1.6.2", 16 | "mongoose": "^5.3.12", 17 | "morgan": "~1.9.0", 18 | "nodemon": "^2.0.3", 19 | "pug": "^3.0.2" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/routes/users.js: -------------------------------------------------------------------------------- 1 | var express = require("express") 2 | var router = express.Router() 3 | 4 | var User = require("../models/user") 5 | 6 | /* GET users listing. */ 7 | router.get("/profile", function(req, res, next) { 8 | user = req.session.user 9 | if (user) res.render("profile", { title: "Profile", user: user }) 10 | else res.redirect("/login") 11 | }) 12 | 13 | router.post("/profile", function(req, res, next) { 14 | var user = req.session.user 15 | if (!user) res.redirect("/login") 16 | console.log('body = ', req.body) 17 | var conditions = { _id: user._id } 18 | var update = { 19 | email: req.body.email, 20 | firstName: req.body.fname, 21 | lastName: req.body.lname 22 | } 23 | var options = {} 24 | User.updateOne(conditions, update, options, (err, numAffected) => { 25 | if (err) throw err 26 | // mongoose query projection; include all attributes but password 27 | // https://mongoosejs.com/docs/api.html#query_Query-projection 28 | User.findById(user._id, '-password', function(err, updateduser) { 29 | if (err) throw err 30 | req.session.user = updateduser 31 | //console.log(updateduser) 32 | // check if request is AJAX 33 | if (req.xhr) 34 | { 35 | // send json data 36 | res.json({msg: 'Profile updated successfully using AJAX!', 37 | user: updateduser 38 | }); 39 | } 40 | // if regular post render the whole profile.pug 41 | else res.render("profile", { 42 | title: "Profile", 43 | user: updateduser, 44 | msg: "Profile updated successfully!" 45 | }); 46 | }) 47 | }) 48 | }) 49 | 50 | module.exports = router 51 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/views/dashboard.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1 Dashboard 5 | h2 Students Grades 6 | if locals.user 7 | h3 Welcome #{user.email}   |    8 | a(href="/users/profile") Profile 9 | |   |    10 | a(href="/logout") Log out 11 | p All Students' Grades 12 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/views/error.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= message 5 | h2= error.status 6 | pre #{error.stack} 7 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/views/index.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= title 5 | p Welcome to #{title} 6 | a(href="/login") Log in 7 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/views/layout.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | title= title 5 | link(rel='stylesheet', href='/stylesheets/style.css') 6 | body 7 | block content 8 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/views/login.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= title 5 | 6 | if locals.error 7 | ul 8 | li= error 9 | 10 | form(method="POST", action="/login", name="login-form") 11 | label(for="email") Email: 12 | br 13 | input(type="text", id="email", name="email", placeholder="Email") 14 | br 15 | label(for="password") Password: 16 | br 17 | input(type="password", id="password", name="password", placeholder="password") 18 | br 19 | br 20 | button(type="submit") Log in 21 | br 22 | h2 Don't have an account yet? 23 | a(href="/signup") Sign up 24 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/views/signup.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= title 5 | if locals.errors 6 | ul 7 | each error in errors 8 | li!= error.msg 9 | 10 | form(method="POST", action="/signup") 11 | label(for="email") Email: 12 | input(type="text", id="email", name="email", required, placeholder="email") 13 | br 14 | br 15 | label(for="password") Password: 16 | input(type="password", id="password", name="password", required, placeholder="password") 17 | br 18 | br 19 | label(for="password1") Password again: 20 | input(type="password", id="password1", name="password1", required, placeholder="re-enter password") 21 | br 22 | br 23 | br 24 | button(type="submit") Sign up 25 | 26 | -------------------------------------------------------------------------------- /ExpressMongoDemos/pug/gradebook-v1/views/users.js: -------------------------------------------------------------------------------- 1 | var express = require("express") 2 | var router = express.Router() 3 | 4 | var User = require("../models/user") 5 | 6 | /* GET users listing. */ 7 | router.get("/profile", function(req, res, next) { 8 | user = req.session.user 9 | if (user) res.render("profile", { title: "Profile", user: user }) 10 | else res.redirect("/login") 11 | }) 12 | 13 | router.post("/profile", function(req, res, next) { 14 | var user = req.session.user 15 | if (!user) res.redirect("/login") 16 | 17 | var conditions = { _id: user._id } 18 | var update = { 19 | email: req.body.email, 20 | firstName: req.body.fname, 21 | lastName: req.body.lname 22 | } 23 | var options = {} 24 | User.update(conditions, update, options, (err, numAffected) => { 25 | if (err) throw err 26 | User.findById(user._id, function(err, updateduser) { 27 | if (err) throw err 28 | req.session.user = updateduser 29 | //console.log(updateduser) 30 | res.render("profile", { 31 | title: "Profile", 32 | user: updateduser, 33 | msg: "Profile updated successfully!" 34 | }) 35 | }) 36 | }) 37 | }) 38 | 39 | module.exports = router 40 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "react": "^17.0.2", 10 | "react-dom": "^17.0.2", 11 | "react-scripts": "4.0.3", 12 | "web-vitals": "^1.0.1" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressMongoDemos/react/authenticate_demo/client/public/favicon.ico -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressMongoDemos/react/authenticate_demo/client/public/logo192.png -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressMongoDemos/react/authenticate_demo/client/public/logo512.png -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/src/App.js: -------------------------------------------------------------------------------- 1 | import logo from './logo.svg'; 2 | import './App.css'; 3 | 4 | function App() { 5 | return ( 6 |
7 |
8 | logo 9 |

10 | Edit src/App.js and save to reload. 11 |

12 | 18 | Learn React 19 | 20 |
21 |
22 | ); 23 | } 24 | 25 | export default App; 26 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/authenticate_demo/client/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-react", 4 | "@babel/preset-env" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/models/user.js: -------------------------------------------------------------------------------- 1 | var mongoose = require("mongoose") 2 | 3 | var Schema = mongoose.Schema 4 | 5 | var UserSchema = new Schema({ 6 | email: { type: String, required: true, max: 100 }, 7 | password: { type: String, required: true, max: 100 }, 8 | firstName: { type: String, required: false, max: 30 }, 9 | lastName: { type: String, required: false, max: 30 } 10 | }) 11 | 12 | // Export model 13 | module.exports = mongoose.model("User", UserSchema, "users") 14 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gradebook", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "nodemon --exec babel-node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "cookie-parser": "~1.4.3", 10 | "debug": "~2.6.9", 11 | "event-stream": "^3.3.4", 12 | "express": "~4.16.0", 13 | "express-react-views": "^0.11.0", 14 | "express-session": "^1.15.6", 15 | "express-validator": "^5.3.0", 16 | "http-errors": "~1.6.2", 17 | "jade": "^0.29.0", 18 | "mongoose": "^5.3.12", 19 | "morgan": "~1.9.0", 20 | "nodemon": "^2.0.3" 21 | }, 22 | "devDependencies": { 23 | "@babel/core": "^7.13.15", 24 | "@babel/node": "^7.13.13", 25 | "@babel/preset-env": "^7.13.15" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/routes/users.js: -------------------------------------------------------------------------------- 1 | var express = require("express") 2 | var router = express.Router() 3 | 4 | var User = require("../models/user") 5 | 6 | /* GET users listing. */ 7 | router.get("/profile", function(req, res, next) { 8 | let user = req.session.user; 9 | console.log('user = ', user); 10 | if (user) res.render("profile", { title: "Profile", user: user}) 11 | else res.redirect("/login") 12 | }) 13 | 14 | router.post("/profile", function(req, res, next) { 15 | var user = req.session.user 16 | if (!user) res.redirect("/login") 17 | console.log('body = ', req.body) 18 | var conditions = { _id: user._id } 19 | var update = { 20 | email: req.body.email, 21 | firstName: req.body.fname, 22 | lastName: req.body.lname 23 | } 24 | var options = {} 25 | User.updateOne(conditions, update, options, (err, numAffected) => { 26 | if (err) throw err 27 | // mongoose query projection; include all attributes but password 28 | // https://mongoosejs.com/docs/api.html#query_Query-projection 29 | User.findById(user._id, '-password', function(err, updateduser) { 30 | if (err) throw err 31 | req.session.user = updateduser 32 | //console.log(updateduser) 33 | // send json data 34 | res.render('profile', {messages: [{msg: 'Profile updated successfully!'}], 35 | user: updateduser 36 | }); 37 | }) 38 | }) 39 | }) 40 | 41 | module.exports = router 42 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/components/header.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressMongoDemos/react/gradebook-v1/views/components/header.jsx -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/components/message.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | function Message(props) { 4 | if (props.messages) 5 | return ( 6 |
    7 | { 8 | props.messages.map(m => ( 9 |
  • {m.msg}
  • 10 | )) 11 | } 12 |
13 | ); 14 | else 15 | return <> ; 16 | } 17 | module.exports = Message; -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/dashboard.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Layout from './Layout' 3 | 4 | function Dashboard(props) { 5 | return ( 6 | 7 |

{props.title}

8 |

Student Grades

9 |

Welcome, {props.user.email}

10 | Profile | Log out 11 |

All Students' Grades

12 |
13 | ); 14 | } 15 | 16 | module.exports = Dashboard; 17 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/error.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Layout from './layout' 3 | 4 | function Error(props) { 5 | return ( 6 | 7 |

{props.title}.

8 |

{props.message}

9 |
10 | ) 11 | } 12 | 13 | module.exports = Error; -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/index.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Layout from './layout' 3 | 4 | function Index(props) { 5 | return ( 6 | 7 |

{props.title}

8 | Log in 9 |
10 | ); 11 | } 12 | 13 | module.exports = Index; -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/layout.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types'; 3 | 4 | 5 | function Layout(props) { 6 | return ( 7 | 8 | 9 | {props.title} 10 | 11 | {/**/} 12 | 13 | 14 | {props.children} 15 |
16 | 17 |
18 | 19 | ); 20 | } 21 | 22 | Layout.propTypes = { 23 | title: PropTypes.string, 24 | }; 25 | 26 | module.exports = Layout; 27 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/login.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Layout from './layout'; 3 | import Message from './components/message' 4 | 5 | 6 | function Login(props) { 7 | return ( 8 | 9 |

Log in

10 | 11 |
12 |
15 | 18 |

19 |
20 |

Don't have an account yet? 21 | Sign up 22 |

23 |
24 |
25 | ); 26 | } 27 | 28 | module.exports = Login; -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/signup.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Layout from './layout'; 3 | import Message from './components/message'; 4 | 5 | function Signup(props) { 6 | return ( 7 | 8 |

{props.title}

9 | 10 |
11 |
14 |
17 | 20 |

21 | 22 |

23 |

Already have an account? Log in

24 |
25 |
26 | ); 27 | } 28 | 29 | module.exports = Signup; 30 | 31 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v1/views/users.js: -------------------------------------------------------------------------------- 1 | var express = require("express") 2 | var router = express.Router() 3 | 4 | var User = require("../models/user") 5 | 6 | /* GET users listing. */ 7 | router.get("/profile", function(req, res, next) { 8 | user = req.session.user 9 | if (user) res.render("profile", { title: "Profile", user: user }) 10 | else res.redirect("/login") 11 | }) 12 | 13 | router.post("/profile", function(req, res, next) { 14 | var user = req.session.user 15 | if (!user) res.redirect("/login") 16 | 17 | var conditions = { _id: user._id } 18 | var update = { 19 | email: req.body.email, 20 | firstName: req.body.fname, 21 | lastName: req.body.lname 22 | } 23 | var options = {} 24 | User.update(conditions, update, options, (err, numAffected) => { 25 | if (err) throw err 26 | User.findById(user._id, function(err, updateduser) { 27 | if (err) throw err 28 | req.session.user = updateduser 29 | //console.log(updateduser) 30 | res.render("profile", { 31 | title: "Profile", 32 | user: updateduser, 33 | msg: "Profile updated successfully!" 34 | }) 35 | }) 36 | }) 37 | }) 38 | 39 | module.exports = router 40 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-react", 4 | "@babel/preset-env" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/README.md: -------------------------------------------------------------------------------- 1 | # gradebook 2 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/models/course.js: -------------------------------------------------------------------------------- 1 | const { ObjectId } = require("bson") 2 | var mongoose = require("mongoose") 3 | 4 | var Schema = mongoose.Schema 5 | 6 | var CourseSchema = new Schema({ 7 | user_id: { type: ObjectId, required: true }, 8 | name: { type: String, required: true, max: 30 }, 9 | fullName: { type: String, required: true, max: 30 }, 10 | crn: { type: Number, required: true, unique: true, dropDups: true }, 11 | section: { type: Number, required: true } 12 | }) 13 | 14 | // Export model 15 | module.exports = mongoose.model("Course", CourseSchema, "courses") 16 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/models/user.js: -------------------------------------------------------------------------------- 1 | var mongoose = require("mongoose") 2 | 3 | var Schema = mongoose.Schema 4 | 5 | var UserSchema = new Schema({ 6 | email: { type: String, required: true, max: 100, required: true, dropDups: true }, 7 | password: { type: String, required: true, max: 100 }, 8 | firstName: { type: String, required: false, max: 30 }, 9 | lastName: { type: String, required: false, max: 30 } 10 | }) 11 | 12 | // Export model 13 | module.exports = mongoose.model("User", UserSchema, "users") 14 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gradebook_v2", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "babel-node ./bin/www", 7 | "dev": "nodemon --exec babel-node ./bin/www" 8 | }, 9 | "dependencies": { 10 | "@babel/core": "^7.13.16", 11 | "@babel/node": "^7.13.13", 12 | "@babel/preset-env": "^7.13.15", 13 | "bcryptjs": "^2.4.3", 14 | "cookie-parser": "~1.4.3", 15 | "debug": "~2.6.9", 16 | "event-stream": "^3.3.4", 17 | "express": "~4.16.0", 18 | "express-react-views": "^0.11.0", 19 | "express-session": "^1.15.6", 20 | "express-validator": "^5.3.1", 21 | "http-errors": "~1.6.2", 22 | "mongoose": "^5.3.12", 23 | "morgan": "~1.9.0", 24 | "react": "^16.14.0", 25 | "react-dom": "^16.13.1" 26 | }, 27 | "devDependencies": { 28 | "nodemon": "^2.0.7" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/routes/users.js: -------------------------------------------------------------------------------- 1 | var express = require("express") 2 | var router = express.Router() 3 | 4 | var User = require("../models/user") 5 | 6 | /* GET users listing. */ 7 | router.get("/profile", function(req, res, next) { 8 | let user = req.session.user; 9 | console.log('user = ', user); 10 | if (user) res.render("profile", { title: "Profile", user: user}) 11 | else res.redirect("/login") 12 | }) 13 | 14 | router.post("/profile", function(req, res, next) { 15 | var user = req.session.user 16 | if (!user) res.redirect("/login") 17 | console.log('body = ', req.body) 18 | var conditions = { _id: user._id } 19 | var update = { 20 | email: req.body.email, 21 | firstName: req.body.fname, 22 | lastName: req.body.lname 23 | } 24 | var options = {} 25 | User.updateOne(conditions, update, options, (err, numAffected) => { 26 | if (err) throw err 27 | // mongoose query projection; include all attributes but password 28 | // https://mongoosejs.com/docs/api.html#query_Query-projection 29 | User.findById(user._id, '-password', function(err, updateduser) { 30 | if (err) throw err 31 | req.session.user = updateduser 32 | //console.log(updateduser) 33 | // send json data 34 | res.render('profile', {messages: [{msg: 'Profile updated successfully!'}], 35 | user: updateduser 36 | }); 37 | }) 38 | }) 39 | }) 40 | 41 | module.exports = router 42 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/components/course.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Layout from '../layout'; 3 | import Message from './message'; 4 | 5 | function Course(props) { 6 | let action = "/course/" 7 | if (props.course) 8 | action += props.course._id 9 | 10 | return ( 11 | 12 |

{props.title}

13 | 14 |
15 |
18 |
21 |
24 |
27 |

28 | 29 |

30 | Cancel 31 |
32 |
33 | ); 34 | } 35 | 36 | module.exports = Course; 37 | 38 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/components/header.jsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressMongoDemos/react/gradebook-v2/views/components/header.jsx -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/components/message.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | function Message(props) { 4 | if (props.messages) 5 | return ( 6 |
    7 | { 8 | props.messages.map(m => ( 9 |
  • {m.msg}
  • 10 | )) 11 | } 12 |
13 | ); 14 | else 15 | return <> ; 16 | } 17 | module.exports = Message; -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/courses.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import course from '../models/course' 3 | import Layout from './layout' 4 | 5 | function CoursesTable(props) { 6 | return ( 7 | 8 | 9 | 10 | 11 | 12 | { 13 | props.courses.map(course => ( 14 | 15 | 16 | 17 | 18 | 19 | )) 20 | } 21 | 22 |
NameFull nameCRNSection
{course.name}{course.fullName}{course.crn}{course.section}
23 | ) 24 | } 25 | 26 | export default function Courses(props) { 27 | let courses; 28 | if (props.courses.length > 0) 29 | courses = 30 | else 31 | courses =

No courses found. Add a new course

32 | 33 | return ( 34 | 35 |

{props.title}

36 | Dashboard | Profile | New Course | Log out 37 |

All Courses

38 | {courses} 39 |
40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/dashboard.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Layout from './layout' 3 | 4 | function Dashboard(props) { 5 | return ( 6 | 7 |

{props.title}

8 |

Student Grades

9 |

Welcome, {props.user.email}

10 | Courses | Profile | Log out 11 |
12 | ); 13 | } 14 | 15 | module.exports = Dashboard; 16 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/error.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Layout from './layout' 3 | 4 | function Error(props) { 5 | return ( 6 | 7 |

{props.title}.

8 |

{props.message}

9 |
10 | ) 11 | } 12 | 13 | module.exports = Error; -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/index.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Layout from './layout' 3 | 4 | function Index(props) { 5 | return ( 6 | 7 |

{props.title}

8 | Log in 9 |
10 | ); 11 | } 12 | 13 | module.exports = Index; -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/layout.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types'; 3 | 4 | function Layout(props) { 5 | return ( 6 | 7 | 8 | {props.title} 9 | 10 | {/**/} 11 | 12 | 13 | 14 | {props.children} 15 |
16 | 17 |
18 | 19 | ); 20 | } 21 | 22 | Layout.propTypes = { 23 | title: PropTypes.string, 24 | }; 25 | 26 | module.exports = Layout; 27 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/login.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Layout from './layout'; 3 | import Message from './components/message' 4 | 5 | 6 | function Login(props) { 7 | return ( 8 | 9 |

Log in

10 | 11 |
12 |
15 | 18 |

19 |
20 |

Don't have an account yet? 21 | Sign up 22 |

23 |
24 |
25 | ); 26 | } 27 | 28 | module.exports = Login; -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/register.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Layout from './layout'; 3 | import Message from './components/message'; 4 | 5 | function Register(props) { 6 | return ( 7 | 8 |

{props.title}

9 | 10 |
11 |
14 |
17 |
20 |
23 | 26 |

27 | 28 |

29 |

Already have an account? Log in

30 |
31 |
32 | ); 33 | } 34 | 35 | module.exports = Register; 36 | 37 | -------------------------------------------------------------------------------- /ExpressMongoDemos/react/gradebook-v2/views/users.js: -------------------------------------------------------------------------------- 1 | var express = require("express") 2 | var router = express.Router() 3 | 4 | var User = require("../models/user") 5 | 6 | /* GET users listing. */ 7 | router.get("/profile", function(req, res, next) { 8 | user = req.session.user 9 | if (user) res.render("profile", { title: "Profile", user: user }) 10 | else res.redirect("/login") 11 | }) 12 | 13 | router.post("/profile", function(req, res, next) { 14 | var user = req.session.user 15 | if (!user) res.redirect("/login") 16 | 17 | var conditions = { _id: user._id } 18 | var update = { 19 | email: req.body.email, 20 | firstName: req.body.fname, 21 | lastName: req.body.lname 22 | } 23 | var options = {} 24 | User.update(conditions, update, options, (err, numAffected) => { 25 | if (err) throw err 26 | User.findById(user._id, function(err, updateduser) { 27 | if (err) throw err 28 | req.session.user = updateduser 29 | //console.log(updateduser) 30 | res.render("profile", { 31 | title: "Profile", 32 | user: updateduser, 33 | msg: "Profile updated successfully!" 34 | }) 35 | }) 36 | }) 37 | }) 38 | 39 | module.exports = router 40 | -------------------------------------------------------------------------------- /ExpressReactDemos/dynamic/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-react", 4 | "@babel/preset-env" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /ExpressReactDemos/dynamic/.gitignore: -------------------------------------------------------------------------------- 1 | public/main.js 2 | -------------------------------------------------------------------------------- /ExpressReactDemos/dynamic/app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var reactViews = require('express-react-views'); 3 | 4 | var app = express(); 5 | 6 | app.set('view engine', 'js'); 7 | app.engine('js', reactViews.createEngine()); 8 | 9 | app.use(express.static(__dirname + '/public')); 10 | 11 | app.get('/', function(req, res) { 12 | var initialState = { 13 | items: [ 14 | {id: 1, text: '1. document your code'}, 15 | {id: 2, text: '2. learn express and react'}, 16 | {id: 3, text: '3. test your code for XSS vulnerability'}, 17 | {id: 4, text: '4. '}, 18 | ], 19 | text: '', 20 | }; 21 | // passing data to Html jsx view 22 | res.render('Html', {data: initialState}); 23 | }); 24 | 25 | var port = process.env.PORT || 3000; 26 | app.listen(port, function() { 27 | console.log('Dynamic react example listening on port ' + port); 28 | }); 29 | -------------------------------------------------------------------------------- /ExpressReactDemos/dynamic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamic-views", 3 | "version": "0.1.0", 4 | "description": "Example of creating a dynamic app using express-react-views", 5 | "author": "Chris Johnson ", 6 | "private": true, 7 | "scripts": { 8 | "start": "browserify -t babelify views/main.js --standalone main -o public/main.js && node app.js" 9 | }, 10 | "dependencies": { 11 | "@babel/preset-env": "^7.0.0", 12 | "@babel/preset-react": "^7.0.0", 13 | "babelify": "^10.0.0", 14 | "browserify": "^14.3.0", 15 | "express": "^4.15.3", 16 | "express-react-views": "0.11.0", 17 | "react": "^16.0.0", 18 | "react-dom": "^16.0.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ExpressReactDemos/dynamic/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/dynamic/public/favicon.ico -------------------------------------------------------------------------------- /ExpressReactDemos/dynamic/readme.md: -------------------------------------------------------------------------------- 1 | Dynamic react views example 2 | =========================== 3 | 4 | This example is the todo list borrowed from the 5 | [react.js main page](http://facebook.github.io/react/). 6 | We render the application server-side using express-react-views. 7 | An initial set of items has been added 8 | to illustrate populating data from the server. 9 | 10 | 11 | run it 12 | ------ 13 | 14 | npm install 15 | npm start 16 | 17 | 18 | How it works 19 | ------------ 20 | 21 | 1. Separate the page into two templates, 22 | a [static container component](views/Html.js) 23 | and a [dynamic inner component](views/Content.js). 24 | 25 | 2. Use express-react-views to render and serve the container. 26 | Server-side data can be sent via view options. 27 | 28 | 3. Make your views available client-side as javascript. 29 | Here I created a [main](views/main.js) function for bootstrapping 30 | and packaged it up using [browserify](http://browserify.org/). 31 | 32 | 4. Initialize the client-side app into the dynamic component 33 | using the same data from the server-side. 34 | This example passes the initial data to the client 35 | as the argument of the main function. 36 | Be mindful of potential XSS vulnerabilities. 37 | -------------------------------------------------------------------------------- /ExpressReactDemos/dynamic/views/main.js: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | var ReactDOM = require('react-dom'); 3 | //var Content = require('./TodoApp'); 4 | var TodoApp = require('./TodoApp'); 5 | 6 | module.exports = function(data, containerId) { 7 | var container = document.getElementById(containerId || 'content'); 8 | ReactDOM.render(, container); 9 | }; 10 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/app.js: -------------------------------------------------------------------------------- 1 | var createError = require('http-errors'); 2 | var express = require('express'); 3 | var path = require('path'); 4 | var cookieParser = require('cookie-parser'); 5 | var logger = require('morgan'); 6 | var cors = require('cors'); 7 | 8 | var indexRouter = require('./routes/index'); 9 | var usersRouter = require('./routes/users'); 10 | var testAPIRouter = require('./routes/testAPI'); 11 | var coursesRouter = require('./routes/courses'); 12 | 13 | var app = express(); 14 | 15 | // view engine setup 16 | app.set('views', path.join(__dirname, 'views')); 17 | app.set('view engine', 'jade'); 18 | 19 | app.use(logger('dev')); 20 | app.use(express.json()); 21 | app.use(express.urlencoded({ extended: false })); 22 | app.use(cookieParser()); 23 | app.use(express.static(path.join(__dirname, 'public'))); 24 | app.use(cors()); // allow cross-origin request 25 | 26 | app.use('/', indexRouter); 27 | app.use('/users', usersRouter); 28 | app.use("/testAPI", testAPIRouter); 29 | app.use("/courses", coursesRouter); 30 | 31 | // catch 404 and forward to error handler 32 | app.use(function(req, res, next) { 33 | next(createError(404)); 34 | }); 35 | 36 | // error handler 37 | app.use(function(err, req, res, next) { 38 | // set locals, only providing error in development 39 | res.locals.message = err.message; 40 | res.locals.error = req.app.get('env') === 'development' ? err : {}; 41 | 42 | // render the error page 43 | res.status(err.status || 500); 44 | res.render('error'); 45 | }); 46 | 47 | module.exports = app; 48 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/data/courses.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "CSCI 106- Web Design I", 4 | "times": 6 5 | }, 6 | { 7 | "name": "CSCI 100- Beg. Python", 8 | "times": 8 9 | }, 10 | { 11 | "name": "CSCI 111- CS1", 12 | "times": 9 13 | }, 14 | { 15 | "name": "CSCI 112- CS2", 16 | "times": 7 17 | }, 18 | { 19 | "name": "CSCI 206- Web2", 20 | "times": 2 21 | }, 22 | { 23 | "name": "CSCI 250- CS3", 24 | "times": 3 25 | }, 26 | { 27 | "name": "CSCI 310- Adv. Python", 28 | "times": 8 29 | }, 30 | { 31 | "name": "CSCI 310- Adv. JavaScript", 32 | "times": 2 33 | }, 34 | { 35 | "name": "CSCI 370- Computer Security", 36 | "times": 5 37 | }, 38 | { 39 | "name": "CSCI 420- Cybersecurity", 40 | "times": 7 41 | }, 42 | { 43 | "name": "CSCI 465- Net/App Security", 44 | "times": 6 45 | }, 46 | { 47 | "name": "CSCI 396- Machine Learning", 48 | "times": 1 49 | } 50 | ] -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "api", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "nodemon ./bin/www" 7 | }, 8 | "dependencies": { 9 | "cookie-parser": "~1.4.4", 10 | "cors": "^2.8.5", 11 | "debug": "~2.6.9", 12 | "express": "~4.16.1", 13 | "http-errors": "~1.6.3", 14 | "jade": "^0.29.0", 15 | "morgan": "~1.9.1" 16 | }, 17 | "devDependencies": { 18 | "nodemon": "^2.0.6" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/routes/courses.js: -------------------------------------------------------------------------------- 1 | let courses = require('../data/courses.json') 2 | 3 | var express = require("express") 4 | var router = express.Router(); 5 | 6 | router.get("/all", function(req, res, next) { 7 | res.json(courses); 8 | }); 9 | 10 | module.exports = router; -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/routes/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET home page. */ 5 | router.get('/', function(req, res, next) { 6 | res.render('index', { title: 'Express' }); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/routes/testAPI.js: -------------------------------------------------------------------------------- 1 | var express = require("express") 2 | var router = express.Router(); 3 | 4 | router.get("/", function(req, res, next) { 5 | res.send("Yay... API is working!"); 6 | }); 7 | 8 | module.exports = router; -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/routes/users.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET users listing. */ 5 | router.get('/', function(req, res, next) { 6 | res.send('respond with a resource'); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/views/error.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= message 5 | h2= error.status 6 | pre #{error.stack} 7 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/views/index.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= title 5 | p Welcome to #{title} 6 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/api/views/layout.jade: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | title= title 5 | link(rel='stylesheet', href='/stylesheets/style.css') 6 | body 7 | block content 8 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.8", 7 | "@testing-library/react": "^11.2.2", 8 | "@testing-library/user-event": "^12.6.0", 9 | "react": "^17.0.1", 10 | "react-dom": "^17.0.1", 11 | "react-scripts": "4.0.1", 12 | "web-vitals": "^0.2.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/express-API-react-client/client/public/favicon.ico -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/express-API-react-client/client/public/logo192.png -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/express-API-react-client/client/public/logo512.png -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/src/components/Courses.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | 4 | class Courses extends React.Component { 5 | constructor(props) { 6 | super(props); 7 | this.state = { 8 | error: null, 9 | isLoaded: false, 10 | courses: "" 11 | }; 12 | this.handleClick = this.handleClick.bind(this); 13 | } 14 | 15 | callAPI() { 16 | const url = "http://localhost:9000/courses/all"; 17 | // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API 18 | fetch(url) 19 | .then(result => result.text() ) 20 | .then(result => { 21 | this.setState({ 22 | courses: JSON.parse(result), 23 | isLoaded: true 24 | }) 25 | }, 26 | (error) => { 27 | this.setState({ 28 | isLoaded: true, 29 | error 30 | }); 31 | }) 32 | } 33 | 34 | handleClick() { 35 | this.callAPI(); 36 | } 37 | 38 | render() { 39 | const { error, isLoaded, courses } = this.state; 40 | if (error) { 41 | return
Error: {error.message}
; 42 | } else if (!isLoaded) { 43 | return ( 44 |
45 | 48 |
49 | ); 50 | } else { 51 | return ( 52 |
53 |
Courses Taught at CMU
54 | { 55 | courses.map( (course) => ( 56 |
57 | 60 |
61 |
62 | )) 63 | } 64 |
65 | ); 66 | } 67 | } 68 | } 69 | 70 | export default Courses; -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want to start measuring performance in your app, pass a function 10 | // to log results (for example: reportWebVitals(console.log)) 11 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 12 | reportWebVitals(); 13 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /ExpressReactDemos/express-API-react-client/client/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/preset-react" 5 | ], 6 | "plugins": [ 7 | [ 8 | "@babel/plugin-proposal-class-properties" 9 | ] 10 | ] 11 | } -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var path = require('path'); 3 | var cookieParser = require('cookie-parser'); 4 | var logger = require('morgan'); 5 | var reactViews = require('express-react-views'); 6 | 7 | var homeRouter = require('./routes/router'); 8 | 9 | var app = express(); 10 | 11 | app.set('views', __dirname + '/views'); 12 | app.set('view engine', 'jsx'); 13 | app.engine('jsx', reactViews.createEngine()); 14 | 15 | app.use(logger('dev')); 16 | app.use(express.json()); 17 | app.use(express.urlencoded({ extended: false })); 18 | app.use(cookieParser()); 19 | app.use(express.static(path.join(__dirname, 'public'))); 20 | 21 | app.use('/', homeRouter); 22 | 23 | module.exports = app; 24 | -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('testapp:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' 62 | ? 'Pipe ' + port 63 | : 'Port ' + port; 64 | 65 | // handle specific listen errors with friendly messages 66 | switch (error.code) { 67 | case 'EACCES': 68 | console.error(bind + ' requires elevated privileges'); 69 | process.exit(1); 70 | break; 71 | case 'EADDRINUSE': 72 | console.error(bind + ' is already in use'); 73 | process.exit(1); 74 | break; 75 | default: 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Event listener for HTTP server "listening" event. 82 | */ 83 | 84 | function onListening() { 85 | var addr = server.address(); 86 | var bind = typeof addr === 'string' 87 | ? 'pipe ' + addr 88 | : 'port ' + addr.port; 89 | debug('Listening on ' + bind); 90 | } 91 | -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/data/background.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "date": "2018 - Present", 4 | "position": "Associate Professor, CMU" 5 | }, 6 | { 7 | "date": "2013 - 2017", 8 | "position": "Assistant Professor, CMU" 9 | }, 10 | { 11 | "date": "2014 - Present", 12 | "position": "Coleman Fellow of Entrepreneurship Education" 13 | }, 14 | { 15 | "date": "2013 - 2017", 16 | "position": "Founder & CEO, iSecureUs, LLC" 17 | }, 18 | { 19 | "date": "2012 - 2013", 20 | "position": "CTO and Partner, Sage Technology Partners, Inc" 21 | }, 22 | { 23 | "date": "2010 - 2012", 24 | "position": "PhD, Phishing Attacks & Machine Learning, New Mexico Tech" 25 | }, 26 | { 27 | "date": "2008 - 2010", 28 | "position": "Research Scientist II, ICASA, New Mexico Tech" 29 | }, 30 | { 31 | "date": "2005 - 2007", 32 | "position": "MS, Computer Science, New Mexico Tech" 33 | }, 34 | { 35 | "date": "2001 - 2004", 36 | "position": "BS, Computer Science, Minor in Math, Colorado Mesa University" 37 | } 38 | ] -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/data/courses.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "CSCI 106- Web Design I", 4 | "times": 6 5 | }, 6 | { 7 | "name": "CSCI 100- Beg. Python", 8 | "times": 8 9 | }, 10 | { 11 | "name": "CSCI 111- CS1", 12 | "times": 9 13 | }, 14 | { 15 | "name": "CSCI 112- CS2", 16 | "times": 7 17 | }, 18 | { 19 | "name": "CSCI 206- Web2", 20 | "times": 2 21 | }, 22 | { 23 | "name": "CSCI 250- CS3", 24 | "times": 3 25 | }, 26 | { 27 | "name": "CSCI 310- Adv. Python", 28 | "times": 8 29 | }, 30 | { 31 | "name": "CSCI 310- Adv. JavaScript", 32 | "times": 2 33 | }, 34 | { 35 | "name": "CSCI 370- Computer Security", 36 | "times": 5 37 | }, 38 | { 39 | "name": "CSCI 420- Cybersecurity", 40 | "times": 7 41 | }, 42 | { 43 | "name": "CSCI 465- Net/App Security", 44 | "times": 6 45 | }, 46 | { 47 | "name": "CSCI 396- Machine Learning", 48 | "times": 1 49 | } 50 | ] -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "testapp", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "nodemon ./bin/www" 7 | }, 8 | "dependencies": { 9 | "cookie-parser": "~1.4.4", 10 | "debug": "~2.6.9", 11 | "express": "~4.16.1", 12 | "express-react-views": "^0.11.0", 13 | "html-react-parser": "^1.2.4", 14 | "morgan": "~1.9.1" 15 | }, 16 | "devDependencies": { 17 | "@babel/plugin-proposal-class-properties": "^7.13.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/EBC.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/EBC.JPG -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/bg-footer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/bg-footer.jpg -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/bg-header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/bg-header.jpg -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/cmu-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/cmu-logo.png -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/contact.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/contact.jpeg -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/favicon_32.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/favicon_32.ico -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/honda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/honda.jpg -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/profile.png -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/research.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/research.jpg -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/resources.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/resources.jpg -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/style.css: -------------------------------------------------------------------------------- 1 | #banner { 2 | background-image: url(bg-header.jpg); 3 | background-repeat: no-repeat; 4 | background-size: cover; 5 | color: white; 6 | text-shadow: 2px 2px rgb(4, 4, 109); 7 | background-color: maroon; 8 | border-radius: 0px; 9 | } 10 | 11 | #footer { 12 | clear: both; 13 | height: 100px; 14 | background: url(bg-footer.jpg); 15 | background-repeat: repeat-x; 16 | background-color: rgb(103, 141, 15); 17 | height: 100px; 18 | } 19 | 20 | .schedule { 21 | text-align: center; 22 | color: white; 23 | } 24 | 25 | #footer { 26 | margin-bottom: 0; 27 | padding-top: 45px; 28 | } 29 | 30 | #currentPage { 31 | color: white; 32 | } -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/assets/teaching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ExpressReactDemos/homepage/public/assets/teaching.png -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/contact.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Layout from './layout' 3 | 4 | class Contact extends React.Component { 5 | constructor(props) { 6 | super(props); 7 | this.state = {}; 8 | } 9 | 10 | render() { 11 | return ( 12 | 13 |
14 |
15 |
16 |

Contact

17 |
18 | Contact 19 |
20 |
21 |
22 |
23 |
24 |

Mailing Address

25 |
26 | Colorado Mesa University
27 | Computer Science and Engineering Department
28 | 1100 North Avenue
29 | Grand Junction, CO 81501
30 |
31 |
32 |

Office

33 |
34 | Confluence Hall
35 | Room: 329
36 | Office Hours: See Here
37 | Twitter
38 |
39 |
40 |
41 |
42 |
43 |
44 | ); 45 | } 46 | } 47 | 48 | export default Contact; -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/includes/background.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import background from '../../data/background.json'; 3 | 4 | class Background extends React.Component { 5 | constructor(props) { 6 | super(props); 7 | this.state = background; 8 | } 9 | 10 | render() { 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | { 21 | this.state.map((b) => ( 22 | 23 | 24 | 25 | 26 | )) 27 | } 28 | 29 |
DatePosition
{ b.date} {b.position }
30 | ); 31 | } 32 | } 33 | 34 | export default Background -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/includes/banner.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | class Banner extends React.Component { 4 | constructor(props) { 5 | super(props); 6 | this.state = { 7 | name: "Dr. Ram Basnet", 8 | title: "Associate Professor of Computer Science", 9 | univer_url: 'http://www.coloradomesa.edu', 10 | univer_logo: '/assets/cmu-logo.png', 11 | }; 12 | } 13 | 14 | render() { 15 | const imgStyle = { 16 | position: "absolute", 17 | top: "5px", 18 | left: "10px", 19 | height: "75px", 20 | }; 21 | 22 | return ( 23 |
24 | 25 | 26 | 27 |

{this.state.name}

28 |

{this.state.title}

29 |
30 | ); 31 | } 32 | } 33 | 34 | module.exports = Banner; -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/includes/courses.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import courses from '../../data/courses.json' 4 | 5 | class Courses extends React.Component { 6 | constructor(props) { 7 | super(props); 8 | this.state = { 9 | }; 10 | } 11 | 12 | render() { 13 | return ( 14 |
15 |

Teaching

16 |
17 | Teaching 18 |
19 |
20 |
Teaching Interests
21 |
    22 |
  • Cybersecurity
  • 23 |
  • Python, C++, JavaScript, Databases
  • 24 |
  • Data Science and ML Applications
  • 25 |
  • Web Design and Secure Web App Development
  • 26 |
27 |
28 |
Courses Taught at CMU
29 | { 30 | courses.map( (course) => ( 31 |
32 | 35 |
36 |
37 | )) 38 | } 39 |
40 | ); 41 | } 42 | } 43 | 44 | export default Courses; -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/includes/footer.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | 4 | 5 | class Footer extends React.Component { 6 | constructor(props) { 7 | super(props); 8 | this.state = { 9 | nav_text: ['Home', 'Teaching', 'Research', 'Resources', 'Contact'], 10 | //nav_urls:['index.html', 'teaching.html', 'research.html', 'resources.html', 'contact.html'], 11 | current_nav: 0 //current navigation id 12 | }; 13 | this.year = new Date(); 14 | this.year = this.year.getFullYear(); 15 | } 16 | 17 | render() { 18 | return ( 19 |

20 | | 21 | { 22 | this.state.nav_text.map((text, index) => 23 |  {text} | 24 | )} 25 |    © {this.year} 26 |

27 | ); 28 | } 29 | } 30 | 31 | module.exports = Footer; -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/includes/navigation.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | class Navbar extends React.Component { 4 | constructor(props) { 5 | super(props); 6 | this.state = { 7 | nav_text: ['Home', 'Teaching', 'Research', 'Resources', 'Contact'], 8 | //nav_urls:['index', 'teaching.html', 'research.html', 'resources.html', 'contact.html'], 9 | activeIndex: 0, //current active navigation id 10 | menu: false 11 | }; 12 | } 13 | 14 | render() { 15 | const show = (this.state.menu) ? "show" : ""; 16 | return ( 17 | 32 | ); 33 | } 34 | } 35 | 36 | export default Navbar; 37 | -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/includes/publication.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import publications from '../../data/publications.json'; 3 | 4 | class Publication extends React.Component { 5 | constructor(props) { 6 | super(props); 7 | this.state = 8 | { 9 | pub: publications 10 | }; 11 | } 12 | 13 | render() { 14 | return ( 15 |
16 |

PUBLICATIONS

17 |
18 | 19 | 20 | { 21 | this.state.pub.map((pub) => ( 22 | 23 | 28 | 29 | )) 30 | } 31 | 32 |
24 | {pub.title}
25 | {pub.author}
26 | {pub.pub_info} 27 |
33 |
34 | ); 35 | } 36 | } 37 | 38 | export default Publication; -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/layout.jsx: -------------------------------------------------------------------------------- 1 | let React = require('react'); 2 | import Banner from './includes/banner'; 3 | import Navigation from './includes/navigation'; 4 | import Footer from './includes/footer'; 5 | 6 | function Layout(props) { 7 | let iconUrl = process.env.PUBLIC_URL+"/assets/favicon_32.ico" 8 | return ( 9 | 10 | 11 | {props.title} 12 | 13 | 14 | 15 | 16 | 17 | 18 | 44 | 45 | 46 | 47 | ); 48 | } 49 | 50 | module.exports = Layout; 51 | -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/research.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Publication from './includes/publication'; 3 | import Layout from './layout'; 4 | 5 | class Research extends React.Component { 6 | constructor(props) { 7 | super(props); 8 | this.state = { 9 | 'interests': ['Phishing attack detection', 'Data science and applications', 10 | 'Network and web application security', 'Computer Science pedagogy'] 11 | }; 12 | } 13 | 14 | render() { 15 | return ( 16 | 17 |
18 |
19 |
20 |

Research

21 |
22 | Research 23 |
24 |
25 |
Research Interests
26 |
    27 | { 28 | this.state.interests.map( (interest) => ( 29 |
  • {interest}
  • 30 | )) 31 | } 32 |
33 |
34 |
Google Scholar
35 |
ResearchGate
36 |
Ungergraduate CS Research
37 |
38 |
39 | 40 |
41 |
42 |
43 | ); 44 | } 45 | } 46 | 47 | export default Research; -------------------------------------------------------------------------------- /ExpressReactDemos/homepage/views/teaching.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Schedule from './includes/schedule'; 3 | import Courses from './includes/courses'; 4 | import Layout from './layout'; 5 | 6 | class Teaching extends React.Component { 7 | constructor(props) { 8 | super(props); 9 | this.state = { 10 | 11 | } 12 | }; 13 | 14 | render() { 15 | return ( 16 | 17 |
18 |
19 | 20 | 21 |
22 |
23 |
24 |
25 | ); 26 | } 27 | } 28 | 29 | export default Teaching; -------------------------------------------------------------------------------- /ExpressReactDemos/simple/app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var http = require('http'); 3 | var path = require('path'); 4 | var errorHandler = require('errorhandler'); 5 | var logger = require('morgan'); 6 | 7 | // This should refer to the local React and gets installed via `npm install` in 8 | // the example. 9 | var reactViews = require('express-react-views'); 10 | 11 | // routes 12 | var routes = require('./routes'); 13 | var user = require('./routes/user'); 14 | 15 | var app = express(); 16 | 17 | // all environments 18 | app.set('port', process.env.PORT || 3000); 19 | app.set('views', __dirname + '/views'); 20 | app.set('view engine', 'jsx'); 21 | app.engine('jsx', reactViews.createEngine()); 22 | 23 | app.use(logger('dev')); 24 | app.use(express.static(path.join(__dirname, 'public'))); 25 | 26 | // development only 27 | if ('development' == app.get('env')) { 28 | app.use(errorHandler()); 29 | } 30 | 31 | app.get('/', routes.index); 32 | app.get('/users', user.list); 33 | 34 | http.createServer(app).listen(app.get('port'), function() { 35 | console.log('Express server listening on port ' + app.get('port')); 36 | }); 37 | -------------------------------------------------------------------------------- /ExpressReactDemos/simple/data/users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "10", 4 | "email": "jdoe@mail.com", 5 | "firstName": "John", 6 | "lastName": "Doe", 7 | "DoB": "01/1/1980" 8 | }, 9 | { 10 | "id": "20", 11 | "email": "jsmith@mail.com", 12 | "firstName": "Jane", 13 | "lastName": "Smith", 14 | "DoB": "01/1/1990" 15 | } 16 | ] -------------------------------------------------------------------------------- /ExpressReactDemos/simple/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple-static-pages", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "nodemon app.js" 7 | }, 8 | "dependencies": { 9 | "errorhandler": "^1.5.0", 10 | "express": "^4.16.1", 11 | "express-react-views": "^0.11.0", 12 | "morgan": "^1.9.0", 13 | "nodemon": "^2.0.7", 14 | "prop-types": "^15.6.0", 15 | "react": "^16.14.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ExpressReactDemos/simple/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } -------------------------------------------------------------------------------- /ExpressReactDemos/simple/routes/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * GET home page. 3 | */ 4 | 5 | exports.index = function(req, res) { 6 | // must use render method 7 | // render index.js view with given context 8 | res.render('index', {title: 'Express', foo: {bar: 'baz'}}); 9 | }; 10 | -------------------------------------------------------------------------------- /ExpressReactDemos/simple/routes/user.js: -------------------------------------------------------------------------------- 1 | /* 2 | * GET users listing. 3 | */ 4 | 5 | exports.list = function(req, res) { 6 | // must use render method 7 | // render users.jsx view with given context 8 | res.render('users', {title: "Users List"}); 9 | //res.send('send user data...'); 10 | }; 11 | -------------------------------------------------------------------------------- /ExpressReactDemos/simple/views/index.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | var PropTypes = require('prop-types'); 3 | var Layout = require('./layout'); 4 | import users from '../data/users.json'; 5 | 6 | // Contrived example to show how one might use Flow type annotations 7 | function countTo(n) { 8 | var a = []; 9 | for (var i = 0; i < n; i++) { 10 | a.push(i + 1); 11 | } 12 | return a.join(', '); 13 | } 14 | 15 | function Title(props) { 16 | return ( 17 |

Welcome to {props.title}

18 | ); 19 | } 20 | 21 | function Index(props) { 22 | return ( 23 | 24 |

{props.title}

25 | 26 | <p> 27 | I can count to 10: 28 | {countTo(10)} 29 | </p> 30 | <table className="table table-striped"> 31 | <tbody> 32 | {users.map( (user) => ( 33 | <tr> 34 | <td>{ user.id }</td> 35 | <td>{ user.email} </td> 36 | <td>{user.firstName}</td> 37 | <td>{user.lastName}</td> 38 | </tr> 39 | ))} 40 | </tbody> 41 | </table> 42 | <div> 43 | <h3><a href="/users">Go to Users Page</a></h3> 44 | </div> 45 | </Layout> 46 | ); 47 | } 48 | 49 | Index.propTypes = { 50 | title: PropTypes.string, 51 | }; 52 | 53 | module.exports = Index; 54 | -------------------------------------------------------------------------------- /ExpressReactDemos/simple/views/layout.jsx: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | var PropTypes = require('prop-types'); 3 | 4 | function Layout(props) { 5 | return ( 6 | <html> 7 | <head> 8 | <title>{props.title} 9 | 10 | {/**/} 11 | 12 | 26 | 27 | 28 | ); 29 | } 30 | 31 | Layout.propTypes = { 32 | title: PropTypes.string, 33 | }; 34 | 35 | module.exports = Layout; 36 | -------------------------------------------------------------------------------- /ExpressReactDemos/simple/views/users.jsx: -------------------------------------------------------------------------------- 1 | const React = require('react') 2 | import users from '../data/users.json'; 3 | import Layout from './layout'; 4 | 5 | class Users extends React.Component { 6 | constructor(props) { 7 | super(props); 8 | this.state = 9 | { 10 | }; 11 | } 12 | 13 | render() { 14 | return ( 15 | 16 | 17 | 18 | {users.map( (user) => ( 19 | 20 | 21 | 22 | 23 | 24 | 25 | ))} 26 | 27 |
{ user.id }{ user.email} {user.firstName}{user.lastName}
28 | 29 |
30 |

Go to Home Page

31 |
32 |
33 | ); 34 | } 35 | } 36 | 37 | module.exports = Users; -------------------------------------------------------------------------------- /JSDemos/async-input.js: -------------------------------------------------------------------------------- 1 | // Reads asynchronously 2 | // Enter some data 3 | console.log('Enter some data: ') 4 | 5 | // use 'data' event 6 | process.stdin.on('data', data => { 7 | data = data.toString().trimEnd(); 8 | console.log(`You typed: ${data}`); 9 | if (data == 'end') 10 | process.exit(); 11 | }); 12 | 13 | process.stdout.write('Good bye!'); 14 | -------------------------------------------------------------------------------- /JSDemos/async-input.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Guess the Number game 3 | By: 4 | Date: 5 | 6 | This program generates a random number between 1 and 20 and asks user to guess that number. 7 | If the user guesses it within 6 turns, s/he wins otherwise loses. 8 | 9 | Algorithm steps: 10 | 1. 11 | 2. 12 | 3. 13 | 14 | */ 15 | 16 | //const readline = require('readline'); 17 | import readline from 'readline' 18 | 19 | const rl = readline.createInterface({ 20 | input: process.stdin, 21 | output: process.stdout 22 | }); 23 | 24 | var name; 25 | console.log("Hi there! What's your name? "); 26 | 27 | rl.on('line', (line) => { 28 | name = line; 29 | console.log('Hello,', name); 30 | console.log('Are you ready to play this game? ') 31 | }); 32 | 33 | console.log('All done!') 34 | -------------------------------------------------------------------------------- /JSDemos/async-input1.js: -------------------------------------------------------------------------------- 1 | 2 | // use 'readable' event 3 | process.stdin.on('readable', () => { 4 | let chunk; 5 | // Use a loop to make sure we read all available data. 6 | while ((chunk = process.stdin.read()) !== null) { 7 | process.stdout.write(`data: ${chunk}`); 8 | if (chunk.toString().trim() === 'end') 9 | process.exit(); 10 | } 11 | }); -------------------------------------------------------------------------------- /JSDemos/async-input2.js: -------------------------------------------------------------------------------- 1 | /* 2 | Guess the Number game 3 | By: 4 | Date: 5 | 6 | This program generates a random number between 1 and 20 and asks user to guess that number. 7 | If the user guesses it within 6 turns, s/he wins otherwise loses. 8 | 9 | Algorithm steps: 10 | 1. 11 | 2. 12 | 3. 13 | 14 | */ 15 | 16 | const readline = require('readline'); 17 | 18 | const rl = readline.createInterface({ 19 | input: process.stdin, 20 | output: process.stdout 21 | }); 22 | 23 | var name; 24 | console.log("Hi there! What's your name? "); 25 | 26 | rl.on('line', (line) => { 27 | name = line; 28 | console.log('Hello,', name); 29 | console.log('Are you ready to play this game? ') 30 | }); 31 | 32 | console.log('All done!') 33 | -------------------------------------------------------------------------------- /JSDemos/circle.js: -------------------------------------------------------------------------------- 1 | /* 2 | This is module 2. Defines question, answer and 3 | circumference function 4 | */ 5 | const assert = require('assert').strict; 6 | //import assert from 'assert'; 7 | //import { fileURLToPath } from 'url'; 8 | 9 | const { PI } = Math; 10 | 11 | var question = "What is your quest?"; 12 | var answer = "To seek the holy grail."; 13 | 14 | function findCircumference(radius) { 15 | /* 16 | Given radius of a circle, finds and returns its circumference. 17 | */ 18 | return 2 * Math.PI * radius; 19 | } 20 | 21 | /* 22 | Given radius of a circle, this funciton finds and returns its area. 23 | */ 24 | let findArea = radius => PI * radius ** 2; 25 | 26 | // CommonJS 27 | module.exports = { findCircumference, findArea }; 28 | 29 | // ESM - EcmaScript Module 30 | //export { findCircumference, findArea }; 31 | 32 | //if (process.argv[1] === fileURLToPath(import.meta.url)) { 33 | if (require.main == module) { 34 | console.log(`question: ${question}`); 35 | console.log(`answer: ${answer}`); 36 | var radius = 2; 37 | var circum = findCircumference(radius); 38 | console.log(`circumference = ${circum.toFixed(2)} unit`); 39 | console.log(`area = ${findArea(radius).toFixed(2)} sq. unit`); 40 | test(); 41 | } 42 | 43 | function test() { 44 | var radius = 2; 45 | var circum = findCircumference(radius); 46 | console.log(circum.toFixed(2)); 47 | assert.strictEqual(circum.toFixed(2), '12.57', 'not equal'); 48 | console.log('all test cases passed!'); 49 | } 50 | -------------------------------------------------------------------------------- /JSDemos/cold/1.ans: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /JSDemos/cold/1.in: -------------------------------------------------------------------------------- 1 | 3 2 | 5 -10 15 3 | -------------------------------------------------------------------------------- /JSDemos/cold/2.ans: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /JSDemos/cold/2.in: -------------------------------------------------------------------------------- 1 | 5 2 | -14 -5 -39 -5 -7 3 | -------------------------------------------------------------------------------- /JSDemos/cold/cold.js: -------------------------------------------------------------------------------- 1 | /* 2 | open.kattis.com 3 | cold problem 4 | - automated testing demo 5 | */ 6 | const readline = require('readline'); 7 | const assert = require('assert').strict; 8 | 9 | function answer(nums) { 10 | var count = 0; 11 | for(var i in nums) { 12 | if (parseInt(nums[i]) < 0) 13 | count += 1; 14 | } 15 | return count; 16 | } 17 | 18 | function test() { 19 | assert.strictEqual(answer([1, 2, -100, 4545, -34343, -3343]), 3); 20 | assert.strictEqual(answer([123, 343, 3434, 34535, 57, 0]), 0); 21 | console.log('all test cases passed...') 22 | } 23 | 24 | function solve() { 25 | const rl = readline.createInterface({ 26 | input: process.stdin, 27 | output: process.stdout 28 | }); 29 | 30 | lineCount = 1; 31 | rl.on('line', (line) => { 32 | //console.log(line); 33 | if (lineCount == 2) { 34 | var nums = line.split(' '); 35 | console.log(answer(nums)); 36 | } 37 | else 38 | lineCount += 1; 39 | }) 40 | } 41 | 42 | if (require.main == module) { 43 | if (process.argv.length > 2 && process.argv[2] === 'test') 44 | test() 45 | else 46 | solve(); 47 | } 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /JSDemos/commandLineArgs.js: -------------------------------------------------------------------------------- 1 | // proces.argv is an array containing the command line arguments 2 | // the first element will be path to node 3 | // the second element will be the name of the JS file 4 | // the next elements will be any additional command line arguments 5 | 6 | for (var index in process.argv) 7 | console.log(index, process.argv[index]); 8 | 9 | // run the program in terminal 10 | // node commandLineArgsDemo.js 11 | // node commandLineArgsDemo.js arg1 arg2 name test key=val 12 | -------------------------------------------------------------------------------- /JSDemos/hello.js: -------------------------------------------------------------------------------- 1 | // open.kattis.com hello problem 2 | // accessing the main module: https://nodejs.org/docs/latest/api/all.html#modules_accessing_the_main_module 3 | 4 | const assert = require('assert').strict; 5 | 6 | function answer() { 7 | return 'Hello World!'; 8 | } 9 | 10 | function solve() { 11 | console.log(answer()); 12 | } 13 | 14 | function test() { 15 | assert.strictEqual(answer(), 'Hello World!'); 16 | console.log('all test cases passed...'); 17 | } 18 | 19 | // if the script file has been run directly using node 20 | if (require.main == module) { 21 | if (process.argv.length > 2 && process.argv[2] == 'test') 22 | test(); 23 | else 24 | solve(); 25 | } -------------------------------------------------------------------------------- /JSDemos/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 |

this is a para....

18 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /JSDemos/input.txt: -------------------------------------------------------------------------------- 1 | first line 2 | hello there! This is second line. 3 | Third line is as plain as This. 4 | Apple 5 | How about ball? 6 | -------------------------------------------------------------------------------- /JSDemos/library/my_math.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert').strict; 2 | 3 | /* 4 | factorial module 5 | */ 6 | 7 | //find the factorial of given n 8 | function factorial(n) { 9 | var fact = 1; 10 | for (var i=2; i<=n; i++) 11 | fact *= i; 12 | return fact; 13 | } 14 | 15 | /* 16 | Given n, the following function finds nth value in fibonacci sequence 17 | */ 18 | var memo = {}; 19 | function fib(n) { 20 | if (n <= 1) 21 | return 1; 22 | if (n in memo) 23 | return memo[n]; 24 | return memo[n] = fib(n-1) + fib(n-2); 25 | } 26 | 27 | function test() { 28 | assert.strictEqual(factorial(5), 120); 29 | assert.strictEqual(factorial(10), 3628800); 30 | assert.strictEqual(factorial(50), 30414093201713378043612608166064768844377641568960512000000000000); 31 | // factorial(100) too large of integer for JS to handle 32 | //assert.strictEqual(factorial(100), 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000); 33 | console.log('all test cases passed...'); 34 | } 35 | 36 | if (require.main == module) { 37 | test(); 38 | } 39 | 40 | module.exports = { fib, factorial }; 41 | 42 | -------------------------------------------------------------------------------- /JSDemos/library/my_math.mjs: -------------------------------------------------------------------------------- 1 | //const assert = require('assert').strict; 2 | import assert from 'assert'; 3 | import {fileURLToPath} from 'url'; 4 | /* 5 | factorial module 6 | */ 7 | 8 | //find the factorial of given n 9 | function factorial(n) { 10 | var fact = 1; 11 | for (var i=2; i<=n; i++) 12 | fact *= i; 13 | return fact; 14 | } 15 | 16 | /* 17 | Given n, the following function finds nth value in fibonacci sequence 18 | */ 19 | var memo = {}; 20 | function fib(n) { 21 | if (n <= 1) 22 | return 1; 23 | if (n in memo) 24 | return memo[n]; 25 | return memo[n] = fib(n-1) + fib(n-2); 26 | } 27 | 28 | function test() { 29 | assert.strictEqual(factorial(5), 120); 30 | assert.strictEqual(factorial(10), 3628800); 31 | assert.strictEqual(factorial(50), 30414093201713378043612608166064768844377641568960512000000000000); 32 | // factorial(100) too large of integer for JS to handle 33 | //assert.strictEqual(factorial(100), 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000); 34 | console.log('all test cases passed...'); 35 | } 36 | 37 | if (process.argv[1] === fileURLToPath(import.meta.url)) { 38 | //if (require.main == module) { 39 | test(); 40 | } 41 | 42 | export { fib, factorial }; 43 | 44 | -------------------------------------------------------------------------------- /JSDemos/moduleDemo.js: -------------------------------------------------------------------------------- 1 | /* 2 | CommonJS Syntax 3 | This is module 1. Declares question, answer, and areaOfCircle function 4 | */ 5 | 6 | const circle = require('./circle'); 7 | const {findCircumference, findArea} = require('./circle'); 8 | // ESM doesn't work! 9 | //const {fib} = require('./library/my_math.mjs') 10 | 11 | // CommonJS module works! 12 | const {fib} = require('./library/my_math.js') 13 | 14 | var question = "What is the meaning of Life, the Universe, and Everything?"; 15 | var answer = 42; 16 | 17 | function main() { 18 | console.log(`question: ${question}`); 19 | console.log(`answer: ${answer}`); 20 | 21 | var area = findArea(10); 22 | console.log(`area = ${area.toFixed(2)} sq. unit`); 23 | var circum = findCircumference(10); 24 | console.log(`circumference = ${circum.toFixed(2)} unit`); 25 | console.log(`Third number in fibonacci seq = ${fib(3)}`); 26 | } 27 | 28 | if (require.main === module) { 29 | main(); 30 | } 31 | -------------------------------------------------------------------------------- /JSDemos/moduleDemo.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | This is module 1. Declares question, answer, and areaOfCircle function 3 | */ 4 | 5 | // ES6 syntax 6 | import {fileURLToPath} from 'url'; 7 | 8 | //const circle = require('./circle'); 9 | // const {findCircumference, findArea} = require('./circle'); 10 | //import {findCircumference, findArea} from './circle.js' 11 | 12 | //const math = require('./library/my_math.js'); 13 | // import all the exported names under math namespace 14 | import { findCircumference, findArea } from './circle.js'; 15 | import * as my_math from './library/my_math.mjs'; 16 | 17 | var question = "What is the meaning of Life, the Universe, and Everything?"; 18 | var answer = 42; 19 | 20 | function main() { 21 | console.log(`question: ${question}`); 22 | console.log(`answer: ${answer}`); 23 | 24 | var area = findArea(10); 25 | console.log(`area = ${area.toFixed(2)} sq. unit`); 26 | var circum = findCircumference(10); 27 | console.log(`circumference = ${circum.toFixed(2)} unit`); 28 | console.log(`Third number in fibonacci seq = ${my_math.fib(3)}`); 29 | } 30 | 31 | if (process.argv[1] === fileURLToPath(import.meta.url)) { 32 | //if (require.main === module) { 33 | main(); 34 | } 35 | -------------------------------------------------------------------------------- /JSDemos/myScript.mjs: -------------------------------------------------------------------------------- 1 | document.write("hello from script file...
"); 2 | window.alert('Hi I am an alert box!'); -------------------------------------------------------------------------------- /JSDemos/oop_static.js: -------------------------------------------------------------------------------- 1 | class Point { 2 | constructor(x, y) { 3 | this.x = x; 4 | this.y = y; 5 | } 6 | 7 | //static displayName = "Point"; 8 | static distance(a, b) { 9 | const dx = a.x - b.x; 10 | const dy = a.y - b.y; 11 | 12 | return Math.hypot(dx, dy); 13 | } 14 | } 15 | 16 | const p1 = new Point(5, 5); 17 | const p2 = new Point(10, 10); 18 | p1.displayName; // undefined 19 | p1.distance; // undefined 20 | p2.displayName; // undefined 21 | p2.distance; // undefined 22 | 23 | console.log(Point.displayName); // "Point" 24 | console.log(Point.distance(p1, p2)); // 7.0710678118654755 -------------------------------------------------------------------------------- /JSDemos/output1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Output Demo 1

5 | 17 |

All done...

18 | 19 | -------------------------------------------------------------------------------- /JSDemos/output2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Output Demo 2

5 |

6 | 9 |

All done...

10 | 11 | -------------------------------------------------------------------------------- /JSDemos/output3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Output Demo 3

5 | 9 |

All done...

10 | 11 | -------------------------------------------------------------------------------- /JSDemos/output4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Output Demo 4

5 | 10 |

All done...

11 | 12 | -------------------------------------------------------------------------------- /JSDemos/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "JSDemo", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "JSDemo", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "chalk": "^5.0.0", 13 | "readline-sync": "^1.4.10" 14 | } 15 | }, 16 | "node_modules/chalk": { 17 | "version": "5.0.0", 18 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.0.tgz", 19 | "integrity": "sha512-/duVOqst+luxCQRKEo4bNxinsOQtMP80ZYm7mMqzuh5PociNL0PvmHFvREJ9ueYL2TxlHjBcmLCdmocx9Vg+IQ==", 20 | "engines": { 21 | "node": "^12.17.0 || ^14.13 || >=16.0.0" 22 | }, 23 | "funding": { 24 | "url": "https://github.com/chalk/chalk?sponsor=1" 25 | } 26 | }, 27 | "node_modules/readline-sync": { 28 | "version": "1.4.10", 29 | "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz", 30 | "integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==", 31 | "engines": { 32 | "node": ">= 0.8.0" 33 | } 34 | } 35 | }, 36 | "dependencies": { 37 | "chalk": { 38 | "version": "5.0.0", 39 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.0.tgz", 40 | "integrity": "sha512-/duVOqst+luxCQRKEo4bNxinsOQtMP80ZYm7mMqzuh5PociNL0PvmHFvREJ9ueYL2TxlHjBcmLCdmocx9Vg+IQ==" 41 | }, 42 | "readline-sync": { 43 | "version": "1.4.10", 44 | "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz", 45 | "integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==" 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /JSDemos/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "JSDemo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "builtinInput.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "chalk": "^5.0.0", 14 | "readline-sync": "^1.4.10" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /JSDemos/packages_demo/chalk-demo.mjs: -------------------------------------------------------------------------------- 1 | import readlineSync from 'readline-sync'; 2 | //const {chalk} = require('chalk'); 3 | import chalk from 'chalk'; 4 | const log = console.log 5 | 6 | var user, pw, command; 7 | 8 | log(chalk.black.bold.bgYellow(' Your Account ')); 9 | user = readlineSync.question(chalk.gray.underline(' USER NAME ') + ' : '); 10 | pw = readlineSync.question(chalk.gray.underline(' PASSWORD ') + ' : ', 11 | {hideEchoBack: true}); 12 | // Authorization ... 13 | log(chalk.green('Welcome, ' + user + '!')); 14 | command = readlineSync.prompt(); 15 | -------------------------------------------------------------------------------- /JSDemos/sync-input.js: -------------------------------------------------------------------------------- 1 | // must install readline-sync package via npm 2 | // https://www.npmjs.com/package/readline-sync 3 | // on terminal: $ npm i readline-sync 4 | const readline = require('readline-sync'); 5 | 6 | var name = readline.question('May I have your name? '); 7 | console.log('Hi there ' + name + '!'); 8 | 9 | var num1 = readline.question("Enter a number between 1 and 20: "); 10 | console.log("Type of num1 is %s", typeof(num1)); 11 | var num2 = Number(num1) ** 2; 12 | console.log("Squared of %s = %s", num1, num2); 13 | 14 | if (readline.keyInYN('Do you want this module?')) { 15 | // 'Y' key was pressed. 16 | console.log('Installing now...'); 17 | // Do something... 18 | } else { 19 | // Another key was pressed. 20 | console.log('Searching another...'); 21 | // Do something... 22 | } 23 | 24 | 25 | animals = ['Lion', 'Elephant', 'Crocodile', 'Giraffe', 'Hippo']; 26 | index = readline.keyInSelect(animals, 'Which animal?'); 27 | //console.log(index) 28 | if (index === -1) 29 | console.log('Cancelling...') 30 | else 31 | console.log('Ok, ' + animals[index] + ' goes to your room.'); 32 | 33 | -------------------------------------------------------------------------------- /JSDemos/unittesting/demo1.js: -------------------------------------------------------------------------------- 1 | const functions = require('./functions'); 2 | const assert = require('assert'); 3 | 4 | // ES6 Module syntax not supported yet by jest 5 | //import * as functions from './functions.js' 6 | //import assert from 'assert' 7 | 8 | function test() { 9 | assert.strictEqual(functions.add(-10, -5), -15, '-5 + -10 != -15'); 10 | assert.strictEqual(functions.add(5, -100), -95, '5 + -100 != -95'); 11 | assert.strictEqual(functions.add(100, 0), 100, '100 + 0 != 100'); 12 | 13 | assert.strictEqual(functions.sub(-10, -5), -5, '-10 - -5 != -5'); 14 | assert.strictEqual(functions.sub(5, -100), 105, '5 - -100 != 105'); 15 | assert.strictEqual(functions.sub(100, 0), 100, '100 - 0 != 100'); 16 | console.log('All test cases passed!'); 17 | } 18 | 19 | 20 | function solve() { 21 | let n1 = 10; 22 | let n2 = 5; 23 | console.log(`${n1} + ${n2} = ${n1+n2}`); 24 | console.log(`${n1} - ${n2} = ${n1-n2}`); 25 | } 26 | 27 | test(); 28 | solve(); 29 | -------------------------------------------------------------------------------- /JSDemos/unittesting/demo2.js: -------------------------------------------------------------------------------- 1 | const functions = require('./functions'); 2 | const url = require('url'); 3 | const assert = require('assert'); 4 | 5 | //import assert from 'assert' 6 | //import { fileURLToPath } from 'url'; 7 | //import * as functions from './functions.js'; 8 | 9 | 10 | 11 | 12 | function test() { 13 | assert.strictEqual(functions.add(-10, -5), -15, '-5 + -10 != -15'); 14 | assert.strictEqual(functions.add(5, -100), -95, '5 + -100 != -95'); 15 | assert.strictEqual(functions.add(100, 0), 100, '100 + 0 != 100'); 16 | 17 | assert.strictEqual(functions.sub(-10, -5), -5, '-10 - -5 != -5'); 18 | assert.strictEqual(functions.sub(5, -100), 105, '5 - -100 != 105'); 19 | assert.strictEqual(functions.sub(100, 0), 100, '100 - 0 != 100'); 20 | console.log('All test cases passed!'); 21 | } 22 | 23 | 24 | function solve() { 25 | let n1 = 10; 26 | let n2 = 5; 27 | console.log(`${n1} + ${n2} = ${n1+n2}`); 28 | console.log(`${n1} - ${n2} = ${n1-n2}`); 29 | } 30 | 31 | if (require.main == module) { 32 | //if (process.argv[1] === url.fileURLToPath(import.meta.url)) { 33 | if (process.argv.length > 2 && process.argv[2] === 'test') 34 | test(); 35 | else 36 | solve(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /JSDemos/unittesting/func_sub.test.js: -------------------------------------------------------------------------------- 1 | 2 | // Use CommonJS syntax (default in NodeJS) 3 | const functions = require('./functions'); 4 | // Use ES6 syntax 5 | // import * as functions from './functions.js' 6 | 7 | test('two minus three is -1', () => { 8 | expect(functions.sub(2, 3)).toBe(-1); 9 | }); 10 | 11 | test('two minus three is five', () => { 12 | expect(functions.sub(2, 3)).toBe(1); 13 | }); 14 | 15 | test('-5 minus -15 equals -20', () => { 16 | expect(functions.sub(-5, -15)).toBe(-20); 17 | }); 18 | 19 | test('subtracting floating point numbers', ()=>{ 20 | expect(functions.sub(3.5, 3.1)).toBeCloseTo(0.4); 21 | }); 22 | 23 | -------------------------------------------------------------------------------- /JSDemos/unittesting/functions.js: -------------------------------------------------------------------------------- 1 | function add(n1, n2) { 2 | return n1+n2; 3 | } 4 | 5 | const sub = (n1, n2) => n1-n2; 6 | 7 | //exports.add = add 8 | //exports.sub = sub; 9 | 10 | //export {add, sub} 11 | module.exports = {add, sub} -------------------------------------------------------------------------------- /JSDemos/unittesting/functions_add.test.js: -------------------------------------------------------------------------------- 1 | 2 | // Use CommonJS format (default in NodeJS) 3 | const functions = require('./functions'); 4 | 5 | test('two plus three is six', () => { 6 | expect(functions.add(2, 3)).toBe(6); 7 | }); 8 | 9 | test('two plus three is five', () => { 10 | expect(functions.add(2, 3)).toBe(5); 11 | }); 12 | 13 | test('-5 plus -15 equals -20', () => { 14 | expect(functions.add(-5, -15)).toBe(-20); 15 | }); 16 | 17 | test('adding floating point numbers correctly', () => { 18 | expect(functions.add(0.1, 0.2)).toBeCloseTo(0.3); 19 | }); 20 | 21 | test('adding floating point numbers fail', () => { 22 | expect(functions.add(0.1, 0.2)).toBe(0.3); // doesn't work because of rounding error 23 | }); -------------------------------------------------------------------------------- /JSDemos/unittesting/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unittest", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "demo1.js", 6 | "scripts": { 7 | "test": "jest", 8 | "start": "node ./bin/www" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "jest": "^26.6.3" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ram Basnet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NextJSDemos/mflix/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | 21 | # debug 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | 26 | # local env files 27 | .env.local 28 | .env.development.local 29 | .env.test.local 30 | .env.production.local 31 | -------------------------------------------------------------------------------- /NextJSDemos/mflix/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-mongodb", 3 | "version": "0.1.0", 4 | "scripts": { 5 | "dev": "next dev", 6 | "build": "next build", 7 | "start": "next start" 8 | }, 9 | "dependencies": { 10 | "mongodb": "^3.5.9", 11 | "next": "latest", 12 | "react": "^16.13.1", 13 | "react-dom": "^16.13.1" 14 | }, 15 | "license": "MIT" 16 | } 17 | -------------------------------------------------------------------------------- /NextJSDemos/mflix/pages/api/movies.js: -------------------------------------------------------------------------------- 1 | // this end point will return 20 movies as json data 2 | 3 | import { connectToDatabase } from "../../util/mongodb"; 4 | 5 | export default async (req, res) => { 6 | const { db } = await connectToDatabase(); 7 | 8 | const movies = await db 9 | .collection("movies") 10 | .find({}) 11 | .sort({ metacritic: -1 }) 12 | .limit(20) 13 | .toArray(); 14 | 15 | res.json(movies); 16 | }; -------------------------------------------------------------------------------- /NextJSDemos/mflix/pages/movies.js: -------------------------------------------------------------------------------- 1 | import { connectToDatabase } from "../util/mongodb"; 2 | 3 | // create React Movies component 4 | export default function Movies({ movies }) { 5 | return ( 6 |
7 |

Top 20 Movies of All Time

8 |

9 | (According to Metacritic) 10 |

11 |
    12 | {movies.map((movie) => ( 13 |
  • 14 |

    {movie.title}

    15 |

    {movie.metacritic}

    16 |

    {movie.plot}

    17 |
  • 18 | ))} 19 |
20 |
21 | ); 22 | } 23 | 24 | export async function getServerSideProps() { 25 | const { db } = await connectToDatabase(); 26 | 27 | const movies = await db 28 | .collection("movies") 29 | .find({}) 30 | .sort({ metacritic: -1 }) 31 | .limit(20) 32 | .toArray(); 33 | 34 | return { 35 | props: { 36 | movies: JSON.parse(JSON.stringify(movies)), 37 | }, 38 | }; 39 | } -------------------------------------------------------------------------------- /NextJSDemos/mflix/pages/top.js: -------------------------------------------------------------------------------- 1 | import { connectToDatabase } from "../util/mongodb"; 2 | 3 | export default function Top({ movies }) { 4 | return ( 5 |
6 |

Top 1000 Movies of All Time

7 |

8 | (According to Metacritic) 9 |

10 |
    11 | {movies.map((movie) => ( 12 |
  • 13 |

    {movie.title}

    14 |

    {movie.metacritic}

    15 |

    {movie.plot}

    16 |
  • 17 | ))} 18 |
19 |
20 | ); 21 | } 22 | 23 | export async function getStaticProps() { 24 | const { db } = await connectToDatabase(); 25 | 26 | const movies = await db 27 | .collection("movies") 28 | .find({}) 29 | .sort({ metacritic: -1 }) 30 | .limit(1000) 31 | .toArray(); 32 | 33 | return { 34 | props: { 35 | movies: JSON.parse(JSON.stringify(movies)), 36 | }, 37 | }; 38 | } -------------------------------------------------------------------------------- /NextJSDemos/mflix/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/NextJSDemos/mflix/public/favicon.ico -------------------------------------------------------------------------------- /NextJSDemos/mflix/public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /NextJSDemos/mflix/util/mongodb.js: -------------------------------------------------------------------------------- 1 | import { MongoClient } from 'mongodb' 2 | 3 | const { MONGODB_URI, MONGODB_DB } = process.env 4 | 5 | if (!MONGODB_URI) { 6 | throw new Error( 7 | 'Please define the MONGODB_URI environment variable inside .env.local' 8 | ) 9 | } 10 | 11 | if (!MONGODB_DB) { 12 | throw new Error( 13 | 'Please define the MONGODB_DB environment variable inside .env.local' 14 | ) 15 | } 16 | 17 | /** 18 | * Global is used here to maintain a cached connection across hot reloads 19 | * in development. This prevents connections growing exponentially 20 | * during API Route usage. 21 | */ 22 | let cached = global.mongo 23 | 24 | if (!cached) { 25 | cached = global.mongo = { conn: null, promise: null } 26 | } 27 | 28 | export async function connectToDatabase() { 29 | if (cached.conn) { 30 | return cached.conn 31 | } 32 | 33 | if (!cached.promise) { 34 | const opts = { 35 | useNewUrlParser: true, 36 | useUnifiedTopology: true, 37 | } 38 | 39 | cached.promise = MongoClient.connect(MONGODB_URI, opts).then((client) => { 40 | return { 41 | client, 42 | db: client.db(MONGODB_DB), 43 | } 44 | }) 45 | } 46 | cached.conn = await cached.promise 47 | return cached.conn 48 | } 49 | -------------------------------------------------------------------------------- /NodeDemos/datetime.js: -------------------------------------------------------------------------------- 1 | exports.myDateTime = () => new Date(); 2 | -------------------------------------------------------------------------------- /NodeDemos/hello-world.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | var dt = require("./datetime"); 3 | 4 | const hostname = "127.0.0.1"; 5 | const port = "9999"; 6 | 7 | const server = http.createServer((request, response) => { 8 | response.writeHead(200, { "Content-Type": "text/html" }); 9 | response.write("

Hello from server...

"); 10 | response.write(`

Current date and time on the server: + 11 | ${dt.myDateTime()} +

`); 12 | response.end(); 13 | }); 14 | 15 | server.listen(port, hostname, err => { 16 | if (err) { 17 | console.log("error occured: ", err); 18 | throw err; 19 | } 20 | console.log(`Server running at http://${hostname}:${port}/`); 21 | }); 22 | -------------------------------------------------------------------------------- /NodeDemos/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | 21 | 22 |

My First HTML Page served by node server...

23 |

This is a paragraph.

24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /NodeDemos/index.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | var fs = require("fs"); 3 | 4 | const hostname = "127.0.0.1"; 5 | const port = "9999"; 6 | 7 | var server = http.createServer((req, res) => { 8 | fs.readFile("index.html", (err, data) => { 9 | if (err) { 10 | res.writeHead(404, { "Content-Type": "text/html" }); 11 | res.write("404 Page Not found!"); 12 | return res.end(); 13 | } 14 | res.writeHead(200, { "Content-Type": "text/html" }); 15 | res.write(data); 16 | return res.end(); 17 | }); 18 | }); 19 | 20 | server.listen(port, hostname, err => { 21 | if (err) { 22 | console.log("error occured: ", err); 23 | throw err; 24 | } 25 | console.log(`Server running at http://${hostname}:${port}/`); 26 | }); 27 | -------------------------------------------------------------------------------- /ReactDemos/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Ram Basnet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ReactDemos/README.md: -------------------------------------------------------------------------------- 1 | # React-Demo-Apps -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/EBC.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/EBC.JPG -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/basnet_icon32.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/basnet_icon32.ico -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/bg-footer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/bg-footer.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/bg-header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/bg-header.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/cmu-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/cmu-logo.png -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/contact.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/contact.jpeg -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/honda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/honda.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/profile.png -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/profile1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/profile1.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/research.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/research.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/resources.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/resources.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/style.css: -------------------------------------------------------------------------------- 1 | #header { 2 | background-image:url(bg-header.jpg); 3 | background-repeat: no-repeat; 4 | background-size: cover; 5 | color: white; 6 | text-shadow: 2px 2px rgb(4, 4, 109); 7 | background-color: maroon; 8 | border-radius: 0px; 9 | } 10 | 11 | #footer { 12 | clear:both; 13 | height:100px; 14 | background:url(bg-footer.jpg); 15 | background-repeat: repeat-x; 16 | background-color: rgb(103, 141, 15); 17 | height: 100px; 18 | } 19 | 20 | .officehour 21 | { 22 | background:#D0F5A9; 23 | font-weight: bolder; 24 | text-align: center; 25 | font-size: 14px; 26 | } 27 | 28 | .schedule 29 | { 30 | background:#FAFFFA; 31 | text-align: center; 32 | font-size: 14px; 33 | } 34 | 35 | #footer { 36 | margin-bottom:0; 37 | padding-top:45px; 38 | } 39 | 40 | #currentPage 41 | { 42 | color: white; 43 | } -------------------------------------------------------------------------------- /ReactDemos/homepage-v0/assets/teaching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v0/assets/teaching.png -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ram Basnet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/README.md: -------------------------------------------------------------------------------- 1 | # Static Site Demo 2 | Demo Nodejs app using express and pug 3 | -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/app.js: -------------------------------------------------------------------------------- 1 | var createError = require("http-errors") 2 | var express = require("express") 3 | var path = require("path") 4 | var cookieParser = require("cookie-parser") 5 | var logger = require("morgan") 6 | 7 | var homeRouter = require("./routes/home") 8 | 9 | var app = express() 10 | 11 | // view engine setup 12 | app.set("views", path.join(__dirname, "views")) 13 | app.set("view engine", "pug") 14 | 15 | app.use(logger("dev")) 16 | app.use(express.json()) 17 | app.use(express.urlencoded({ extended: false })) 18 | app.use(cookieParser()) 19 | 20 | app.use(express.static(path.join(__dirname, "public"))) 21 | app.use("/home", express.static(path.join(__dirname, "public"))) 22 | 23 | // add your routers 24 | app.use("/", homeRouter) 25 | 26 | // catch 404 and forward to error handler 27 | app.use(function(req, res, next) { 28 | next(createError(404)) 29 | }) 30 | 31 | // error handler 32 | app.use(function(err, req, res, next) { 33 | // set locals, only providing error in development 34 | res.locals.message = err.message 35 | res.locals.error = req.app.get("env") === "development" ? err : {} 36 | 37 | // render the error page 38 | res.status(err.status || 500) 39 | res.render("error") 40 | }) 41 | 42 | module.exports = app 43 | -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "expressdemo", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "nodemon ./bin/www", 7 | "compile": "webpack" 8 | }, 9 | "dependencies": { 10 | "cookie-parser": "~1.4.3", 11 | "debug": "~2.6.9", 12 | "express": "~4.16.0", 13 | "http-errors": "~1.6.2", 14 | "morgan": "~1.9.0", 15 | "nodemon": "^2.0.7", 16 | "pug": "^3.0.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/EBC.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/EBC.JPG -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/basnet_icon32.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/basnet_icon32.ico -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/bg-footer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/bg-footer.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/bg-header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/bg-header.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/cmu-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/cmu-logo.png -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/contact.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/contact.jpeg -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/honda.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/honda.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/profile.png -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/profile1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/profile1.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/research.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/research.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/resources.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/resources.jpg -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/style.css: -------------------------------------------------------------------------------- 1 | #header { 2 | background-image:url(bg-header.jpg); 3 | background-repeat: no-repeat; 4 | background-size: cover; 5 | color: white; 6 | text-shadow: 2px 2px rgb(4, 4, 109); 7 | background-color: maroon; 8 | border-radius: 0px; 9 | } 10 | 11 | #footer { 12 | clear:both; 13 | height:100px; 14 | background:url(bg-footer.jpg); 15 | background-repeat: repeat-x; 16 | background-color: rgb(103, 141, 15); 17 | height: 100px; 18 | } 19 | 20 | .officehour 21 | { 22 | background:#D0F5A9; 23 | font-weight: bolder; 24 | text-align: center; 25 | font-size: 14px; 26 | } 27 | 28 | .schedule 29 | { 30 | background:#FAFFFA; 31 | text-align: center; 32 | font-size: 14px; 33 | } 34 | 35 | #footer { 36 | margin-bottom:0; 37 | padding-top:45px; 38 | } 39 | 40 | #currentPage 41 | { 42 | color: white; 43 | } -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/assets/teaching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rambasnet/NodeJS/b5c4163fd4c7c572545ecbb30efb15bd49b7db9f/ReactDemos/homepage-v1/public/assets/teaching.png -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /ReactDemos/homepage-v1/public/ui/footer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | Goal is to render the following HTML: 5 | 6 |

Home | Teaching | 7 | Research | Resources | 8 | Contact       9 | © 2018 10 |

11 | */ 12 | 13 | class Footer extends React.Component { 14 | constructor(props) { 15 | super(props); 16 | this.state = { 17 | nav_text: ['Home', 'Teaching', 'Research', 'Resources', 'Contact'], 18 | nav_urls: ['index.html', 'teaching.html', 'research.html', 'resources.html', 'contact.html'], 19 | current_nav: 0 //current navigation id 20 | }; 21 | this.year = new Date(); 22 | this.year = this.year.getFullYear(); 23 | } 24 | 25 | render() { 26 | return ( 27 |

28 | | 29 | { 30 | this.state.nav_text.map((text, index) => 31 |  {text} | 32 | )} 33 |    © {this.year} 34 |

35 | ); 36 | } 37 | } 38 | 39 | ReactDOM.render( 40 |