Skip to content

Commit 61d5e85

Browse files
authored
Merge pull request #81 from Dynamsoft/_dev
add readme.node.md
2 parents 95919a8 + 0955135 commit 61d5e85

File tree

3 files changed

+177
-2
lines changed

3 files changed

+177
-2
lines changed

README.NODE.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Dynamsoft JavaScript Barcode SDK for Node
2+
3+
> This library is the Node.js edition of Dynamsoft Barcode Reader. If you are looking to implement barcode reading feature in a web page, please check out the other library [Dynamsoft JavaScript Barcode SDK for Web](https://github.com/dynamsoft-dbr/javascript-barcode/).
4+
5+
Both 1D and 2D barcode symbiology are supported including the popular `Code 39`, `EAN-13`, `QR`, `PDF417`, etc.+ Find the full list [here](https://www.dynamsoft.com/Products/Dynamic-Barcode-Reader.aspx).
6+
7+
The library is based on `webassembly` which has been an official feature of Node.js since `LTS 8`. If you are using Node.js LTS 8 and have no plan to upgrade it, check out [how to use the library in Node.js LTS 8](#how-to-use-the-library-in-nodejs-lts-8). That said, Node.js version >= LTS 12 is recommended because the library will try to use `worker_threads` when decoding.
8+
9+
> Also see [Dynamsoft JavaScript Barcode SDK for Web](https://github.com/Dynamsoft/javascript-barcode/blob/master/README.md).
10+
11+
## Get Started
12+
13+
* Check your Node.js version
14+
15+
```shell
16+
> node -v
17+
v12.13.1
18+
```
19+
20+
* Installs the library from npm
21+
22+
```shell
23+
> npm install dynamsoft-javascript-barcode --save
24+
```
25+
* Create a `js` file and include the library
26+
27+
```js
28+
let DBR = require("dynamsoft-javascript-barcode");
29+
```
30+
31+
The following also works
32+
```js
33+
let DBR = require("path/to/dist/dbr.js");
34+
```
35+
36+
> **Note**
37+
> The library uses `Promise` a lot, so it's recommended to write the related code in a `async` function so that later you can use `await`
38+
>
39+
> ```js
40+
> (async()=>{
41+
> // many work will done here
42+
> })();
43+
> ```
44+
45+
* Create an instance of the reader
46+
47+
```js
48+
let reader = await DBR.BarcodeReader.createInstance();
49+
```
50+
51+
* Decode a file by its path
52+
53+
```js
54+
let results = await reader.decode('path/to/sample.png');
55+
```
56+
57+
Or just decode a file by its URL
58+
59+
```js
60+
let results = await reader.decode('https://demo.dynamsoft.com/barcode-reader/img/AllSupportedBarcodeTypes.png');
61+
```
62+
> **NOTE**
63+
> The following image formats are supported by default: `png`, `jpg`, `bmp`, `gif`.
64+
>
65+
> If you want to decode other files like `pdf`'s, you need to convert them to images first. Contact [Dynamsoft Support](https://www.dynamsoft.com/Company/Contact.aspx) to find out more.
66+
>
67+
> If you want to decode raw image data (`RGBA`) from sources like a camera. You can use the API `deocdeBuffer`. Check out [C++ API decodeBuffer](https://www.dynamsoft.com/barcode-reader/programming/cplusplus/api-reference/cbarcodereader-methods/decode.html?ver=latest#decodebuffer) for more details.
68+
69+
* Print out the results
70+
71+
```js
72+
for(let result of results){
73+
console.log(result.barcodeText);
74+
}
75+
```
76+
77+
* Run your code.
78+
79+
```shell
80+
> node your-code.js
81+
```
82+
83+
Last not but least, don't forget to set a `productKey`! If you don't have a key yet, click [here](https://www.dynamsoft.com/customer/license/trialLicense) to get one.
84+
85+
```js
86+
DBR.BarcodeReader.productKeys = 'PRODUCT-KEYS';
87+
```
88+
89+
**Full code**
90+
91+
```js
92+
let DBR = require('dynamsoft-node-barcode');
93+
// Please visit https://www.dynamsoft.com/customer/license/trialLicense to get a trial license
94+
DBR.BarcodeReader.productKeys = 'PRODUCT-KEYS';
95+
96+
(async()=>{
97+
let reader = await DBR.BarcodeReader.createInstance();
98+
for(let result of await reader.decode('https://demo.dynamsoft.com/barcode-reader/img/AllSupportedBarcodeTypes.png')){
99+
console.log(result.barcodeText);
100+
}
101+
reader.destroy();
102+
103+
// Since the worker keep alive, you can call
104+
await DBR.BarcodeReader._dbrWorker.terminate();
105+
// when you need to exit this process.
106+
// Or call
107+
process.exit();
108+
// directly.
109+
})();
110+
111+
```
112+
113+
## Change Decoding Settings
114+
115+
To set up the library for decoding, use the APIs `getRuntimeSettings` & `updateRuntimeSettings`.
116+
117+
```js
118+
await barcodeScanner.updateRuntimeSettings("speed");
119+
```
120+
```js
121+
await barcodeScanner.updateRuntimeSettings("balance");
122+
```
123+
```js
124+
await barcodeScanner.updateRuntimeSettings("coverage");
125+
```
126+
```js
127+
let settings = await reader.getRuntimeSettings();
128+
settings.localizationModes = [
129+
Dynamsoft.DBR.EnumLocalizationMode.LM_CONNECTED_BLOCKS,
130+
Dynamsoft.DBR.EnumLocalizationMode.LM_SCAN_DIRECTLY,
131+
Dynamsoft.DBR.EnumLocalizationMode.LM_LINES, 0, 0, 0, 0, 0];
132+
settings.deblurLevel = 2;
133+
await reader.updateRuntimeSettings(settings);
134+
```
135+
136+
See [Barcode reading settings Guide](https://www.dynamsoft.com/barcode-reader/programming/cplusplus/user-guide.html?ver=latest#use-publicruntimesettings-struct-to-change-settings) for basic usage.
137+
138+
See [C++ API RuntimeSettings](https://www.dynamsoft.com/barcode-reader/programming/c-cplusplus/struct/PublicRuntimeSettings.html) for more details.
139+
140+
To find out which settings best suit your usage scenario, visit [DBR Main Online Demo](https://demo.dynamsoft.com/dbr/barcodereaderdemo.aspx).
141+
142+
Any questions, please contact [Dynamsoft support](https://www.dynamsoft.com/Company/Contact.aspx).
143+
144+
145+
146+
## How to use the library in Node.js LTS 8
147+
148+
Node.js LTS 8 doesn't support `worker_threads`, so the decoding will happen in the same main thread which means it's a blocking operation. The following code snippets demonstrate the basic usage.
149+
150+
**Decode**
151+
152+
```js
153+
var dbr = require('path/to/dist/dbr-<version>.node.wasm.js');
154+
dbr.onRuntimeInitialized = ()=>{
155+
dbr.BarcodeReaderWasm.init('{"productKeys":"PRODUCT-KEYS"}');
156+
var reader = new dbr.BarcodeReaderWasm(false,-1);
157+
var fs = require('fs');
158+
var img = fs.readFileSync('./sample.png');
159+
var resultsInfo = JSON.parse(reader.decodeFileInMemory(new Uint8Array(img)));
160+
console.log(resultsInfo);
161+
};
162+
```
163+
164+
**Change settings**
165+
166+
```js
167+
var settings = JSON.parse(reader.getRuntimeSettings());
168+
settings.expectedBarcodesCount = 999;
169+
reader.updateRuntimeSettings(JSON.stringify(settings));
170+
```
171+
172+
173+
174+
175+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ await scanner.updateRuntimeSettings(settings);
558558

559559
## Self-hosted | Offline | Intranet Deployment
560560

561-
For commercial usage, we highly recommend self-hosted deployment. The following steps guide you through how to deploy the library on your own server.
561+
For commercial usage, we highly recommend self-hosted deployment and use reliable commercial CDN to accelerate. The following steps guide you through how to deploy the library on your own server.
562562

563563
* **Step one**: Place the files
564564

doc/api reference/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ <h3>Read a specific area/region</h3>
655655
<a href="#self-hosted--offline--intranet-deployment" id="self-hosted--offline--intranet-deployment" style="color: inherit; text-decoration: none;">
656656
<h2>Self-hosted | Offline | Intranet Deployment</h2>
657657
</a>
658-
<p>For commercial usage, we highly recommend self-hosted deployment. The following steps guide you through how to deploy the library on your own server.</p>
658+
<p>For commercial usage, we highly recommend self-hosted deployment and use reliable commercial CDN to accelerate. The following steps guide you through how to deploy the library on your own server.</p>
659659
<ul>
660660
<li><strong>Step one</strong>: Place the files</li>
661661
</ul>

0 commit comments

Comments
 (0)