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
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 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 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 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 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 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
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 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 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 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
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 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 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); |
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 queryResponse = await container.items.query( | |
"SELECT * FROM c WHERE c.id='" + newItemId + "'").toArray(); | |
console.log(queryResponse.result[0].name); |
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
// Delete item | |
const deleteResponse = await container.item(newItemId).delete(); | |
console.log(deleteResponse.item.id); | |
// Read all items from the container | |
const docResponse = await container.items.readAll().toArray(); | |
res.send(docResponse); |
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
// 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!"); | |
}); |
OlderNewer