This file contains 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
var weight = -12.2; | |
try { | |
if (weight < 0) { | |
throw "Weight can not be less than 0"; | |
} | |
console.log("Saving today's weight to database..."); | |
} catch(error) { | |
console.log(error); | |
} |
This file contains 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 request = require("request"); | |
request("https://www.andreasjakl.com/", function(error, response, body) { | |
if (error) { | |
// Handle error | |
console.log("Error: ", error); | |
} else { | |
// Successful request | |
console.log("body: ", body); | |
} |
This file contains 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 request = require("request"); | |
request("https://www.andreasjakl.com/", handleResponse); | |
function handleResponse(error, response, body) { | |
if (error) { | |
// Handle error | |
console.log("Error: ", error); | |
} else { | |
// Successful request |
This file contains 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
request("https://www.andreasjakl.com/wp-content/uploads/2018/08/arcore-anchors.gif", function(error, response, body) { | |
if (error) { | |
// Handle error | |
console.log("Error: ", error); | |
} else { | |
if (response && response.statusCode == 200) { | |
request("https://www.andreasjakl.com/wp-content/uploads/2018/08/SLAM-HoloLens-2000x1163.jpg", function(error, response, body) { | |
if (error) { | |
console.log("Error: ", error); | |
} else { |
This file contains 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 rp = require("request-promise-native"); | |
rp("https://www.andreasjakl.com/") | |
.then(function(response) { | |
// Start second request, e.g., based on results of first request | |
console.log("Response length: ", response.length); | |
if (response.length > 100) { | |
return rp("https://www.andreasjakl.com/wp-content/uploads/2018/08/arcore-anchors.gif"); | |
} | |
}) |
This file contains 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 rp = require("request-promise-native"); | |
async function processData() { | |
try { | |
let response = await rp("https://www.andreasjakl.com/"); | |
if (response.length > 100) { | |
let response2 = await rp("https://www.andreasjakl.com/wp-content/uploads/2018/08/arcore-anchors.gif"); | |
console.log("Data: ", response2.substring(0,10)); | |
} | |
} catch (error) { |
This file contains 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
// Import the "express" module for more powerful web server capabilities. | |
const express = require('express'); | |
// Initialize the express module and make it accessible via the app variable. | |
const app = express() | |
app.get('/', async (req, res) => { | |
// We'll write all our code here. For now, to test | |
res.end("Hello DB!"); | |
}); |
This file contains 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('/', async (req, res) => { | |
// Import database node module | |
const CosmosClientInterface = require("@azure/cosmos").CosmosClient; | |
// Database and container IDs | |
const databaseId = "ToDoList"; | |
const containerId = "Items"; | |
// Configure database access URI and primary key | |
const endpoint = "https://<...>.documents.azure.com:443/"; |
This file contains 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
try { | |
// Open a reference to the database | |
const dbResponse = await cosmosClient.databases.createIfNotExists({ | |
id: databaseId | |
}); | |
var database = dbResponse.database; | |
// ... (we will add more code here!) | |
res.send("Finished"); |
This file contains 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 newItemId = Math.floor(Math.random() * 1000 + 10).toString(); | |
let documentDefinition = { | |
"id": newItemId, | |
"name": "Angus MacGyver", | |
"state": "Building stuff" | |
}; | |
// Add a new item to the container | |
console.log("** Create item **"); | |
const createResponse = await container.items.create(documentDefinition); |
OlderNewer