This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get("/:user", (req, res) => { | |
| collection.find({ user: req.params.user }).toArray((err, docs) => { | |
| if (err) { // if an error occurred | |
| res.send("An error occured in getting the user info."); | |
| } else { | |
| // there were matches (there are users with that username) | |
| if (docs.length > 0) { | |
| // get the first users password (each user should have a unique username) | |
| let password = docs[0].pass; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.get("/:user", (req, res) => { | |
| console.log(`Password: ${req.query.pass}`); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The URL for the request. | |
| // Remember that the first route parameter is the username of the user to create | |
| const postURL = 'http://localhost:4567/deb'; | |
| // The data will be sent in the `body` property of | |
| // the fetch request and stored with the user data in the database (collection) | |
| const userData = { | |
| // Remember that we don't have to specify the username in the data | |
| // sent with the request because the server inserts the username from the URL into the data sent to the Mongo collection. | |
| pass: '1234' // here is the user password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The URL for the request. | |
| // Remember that the first route parameter is the username of the user to create | |
| const postURL = 'http://localhost:4567/dan'; | |
| // The extra data will be sent in the `body` property of | |
| // the fetch request and stored with the user data in the database (collection) | |
| const extraDataToStore = { | |
| myNewAwesomeData: 'wohooo!', | |
| eyeColor: 'not blue', | |
| hairColor: 'brown---ish', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The URL for the request. | |
| // Remember that the first route parameter is the username of the user to get information about | |
| const postURL = 'http://localhost:4567/dan'; | |
| fetch(postURL, { | |
| method: 'get', // Using get request to recieve database resources | |
| mode: 'cors', // no-cors, cors, *same-origin | |
| cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached | |
| credentials: 'same-origin', // include, *same-origin, omit | |
| headers: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The URL for the request. | |
| // Remember that the first route parameter is the username of the user to create | |
| const postURL = 'http://localhost:4567/dan'; | |
| // The extra data will be sent in the `body` property of | |
| // the fetch request and stored with the user data in the database (collection) | |
| const extraDataToStore = { | |
| eyeColor: 'blue', | |
| hairColor: 'brown', | |
| pass: 'mypassword123' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // init project | |
| const express = require("express"); // the library we will use to handle requests | |
| const mongodb = require("mongodb"); // load mongodb | |
| const port = 4567; // port to listen on | |
| const app = express(); // instantiate express | |
| app.use(require("cors")()); // allow Cross-domain requests | |
| app.use(require("body-parser").json()); // automatically parses request data to JSON |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log(dimensions.sources); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const dimensions = await page.evaluate(() => { | |
| let sources = []; // an array of the links to each image | |
| document.querySelectorAll( | |
| "#react-root > div > div > div > main > div > div.css-1dbjc4n.r-aqfbo4.r-1niwhzg.r-16y2uox > div > div.css-1dbjc4n.r-14lw9ot.r-1tlfku8.r-1ljd8xs.r-13l2t4g.r-1phboty.r-1jgb5lz.r-1ye8kvj.r-13qz1uu.r-184en5c > div > div > div.css-1dbjc4n.r-1jgb5lz.r-1ye8kvj.r-6337vo.r-13qz1uu > div > section > div > div > div img" | |
| ).forEach(img => { | |
| if (img.src) { | |
| sources.push(img) | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.querySelector( | |
| "#react-root > div > div > div > main > div > div.css-1dbjc4n.r-aqfbo4.r-1niwhzg.r-16y2uox > div > div.css-1dbjc4n.r-14lw9ot.r-1tlfku8.r-1ljd8xs.r-13l2t4g.r-1phboty.r-1jgb5lz.r-1ye8kvj.r-13qz1uu.r-184en5c > div > div > div.css-1dbjc4n.r-1jgb5lz.r-1ye8kvj.r-6337vo.r-13qz1uu > div > section > div > div > div" | |
| ); | |
| // the above returns the div for the middle column twitter feed |