I'm following some Microsoft learning paths these days, with the objective of gain the skills needed to become an "Azure Data Engineer" (DP-200-201 or DP-203 Certification).
I was trying to complete the exercise "Connect an app to Azure Storage Exercise - Upload an image to your Azure Storage account" using the sandbox provided by Microsoft, and coding some Node.js lines like this:
async function main() {
// Create a container (folder) if it does not exist
...
// Upload the file
...
// Get a list of all the blobs in the container
let blobs = containerClient.listBlobsFlat();
for await (const blob of blobs) {
console.log(`${blob.name} --> Created: ${blob.properties.createdOn}
Size: ${blob.properties.contentLength}`)
}
}
main();
when I faced the following error (working from Azure Cloud Shell):
home/morales4dev/PhotoSharingApp/index.js:22
for await (const blob of blobs) {
^^^^^
SyntaxError: Unexpected reserved word
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
The guide notes that if we get an error about the use of the await keyword, we must be sure we have added the async keyword to the main function definition.
But we had it!
Then, I remembered that for-await loops are first available in Node.js in version 10, so I suspected that I was probably using an earlier node version.
Let's checkout node version:
morales4dev@Azure:~/PhotoSharingApp$ node --version
v8.16.0
We upgraded Node.js version (if you don't know how to do it, you can follow some guide like this), and after the upgrade:
morales4dev@Azure:~/PhotoSharingApp$ node --version
v14.15.5
Now the code works as expected:
node index.js
Hello, World!
Create container photos successfully false
docs-and-friends-selfie-stick.png --> Created: Sat Feb 20 2021 08:48:49
GMT+0000 (Coordinated Universal Time) Size: 19693
It's a bit tricky that the provisioned development environment doesn't meet the requirements to run the proposed code, but... if things like this don't happen, it would be too easy.