Skip to content

Commit

Permalink
feat: added example (#7)
Browse files Browse the repository at this point in the history
* feat: added example

* refactor: added node EOL in example
  • Loading branch information
aarontravass authored Dec 17, 2023
1 parent 13255bb commit de85b31
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/simplequeue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { AzureQueueConsumer } from 'az-queue-consumer'
import { readFileSync } from 'node:fs'
import { EOL } from 'node:os'

// read .env file
;(() =>
readFileSync('./.env', { encoding: 'utf-8' })
.toString()
.split(EOL)
.forEach((env) => {
for (let end = 0; end < env.length; end++) {
if (env.charAt(end) == '=') {
const key = env.slice(0, end)
let value = env.slice(end + 1)
if (value.charAt(0) == "'") value = value.slice(1)
if (value.charAt(value.length - 1) == "'") value = value.slice(0, value.length - 1)
process.env[key] = value
break
}
}
}))()

const client = new AzureQueueConsumer(
process.env.AZURE_QUEUE_NAME!,
process.env.AZURE_STORAGE_ACCOUNT_CONNECTION_STRING!,
(messages) => {
console.log(messages)
}
)
client.listen()
18 changes: 18 additions & 0 deletions examples/simplequeue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "simplequeue",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsx index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"tsx": "^3.13.0"
},
"dependencies": {
"az-queue-consumer": "^1.0.3"
}
}

0 comments on commit de85b31

Please sign in to comment.