/
example.js
37 lines (30 loc) · 922 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(async () => {
require('dotenv').config()
const log = data => console.log(JSON.stringify(data, null, 2))
const CONTAINER = 'testcontainer'
const FILE = 'test.json'
const storage = require('../src/index')({
connectionString: process.env.BLOB_SERVICE_SAS_URL
})
try {
// List containers
log(await storage.list())
// Create container
log(await storage.create(CONTAINER))
// Create container connection
const container = storage.container(CONTAINER)
// List blobs in container
log(await container.list())
// Write text to blob
log(await container.writeText(FILE, JSON.stringify({ text: 'The world is beautiful' })))
// Read blob
log(await container.read(FILE))
// Delete blob
log(await container.remove(FILE))
// Delete container
log(await storage.remove(CONTAINER))
} catch (error) {
console.log('ERROR:')
log(error)
}
})()