Skip to content

Commit

Permalink
Update npm example
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Jun 10, 2020
1 parent a119a20 commit 7e4188e
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions js/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
1. Setup the API
```js
const qz = require("qz-tray");

```js
qz.api.setPromiseType(function promise(resolver) { return new Promise(resolver); });
qz.api.setWebSocketType(require('ws'));

// Node 4.5
var createHash = require('sha.js');
qz.api.setSha256Type(function(data) {
return createHash('sha256').update(data).digest('hex');
});
```

2. Code

```js
var qz = require("qz-tray");
// Start promise chain
qz.websocket.connect().then(function() {
return qz.printers.find();
}).then(function(printers) {
console.log(printers);
}).then(function() {
return qz.websocket.disconnect();
}).then(function() {
process.exit(0);
}).catch(function(err) {
console.error(err);
process.exit(1);
});
```
qz.websocket.connect().then(() => {
return qz.printers.find();
}).then((printers) => {
console.log(printers);
let config = qz.configs.create('PDF');
return qz.print(config, [{
type: 'pixel',
format: 'html',
flavor: 'plain',
data: '<h1>Hello JavaScript!</h1>'
}]);
}).then(() => {
return qz.websocket.disconnect();
}).then(() => {
// process.exit(0);
}).catch((err) => {
console.error(err);
// process.exit(1);
});
```

0 comments on commit 7e4188e

Please sign in to comment.