Example of how to validate barcode scans in real-time using NodeJS and express framework.
First ensure you have Node.js installed:
# should return 11 or higher
node -v
Then execute the following:
# download this example code
git clone https://github.com/orca-scan/orca-validation-node.git
# go into the new directory
cd orca-validation-node
# install dependencies
npm install
# start the project
npm start
Your server will now be running on port 3000.
You can emulate an Orca Scan Validation input using cURL by running the following:
curl --location --request POST 'http://localhost:3000/' \
--header 'Content-Type: application/json' \
--data-raw '{
"___orca_sheet_name": "Vehicle Checks",
"___orca_user_email": "[email protected]",
"Barcode": "orca-scan-test",
"Date": "2022-04-19T16:45:02.851Z",
"Name": "Orca Scan Validation"
}'
- Only Orca Scan system fields start with
___
- Properties in the JSON payload are an exact match to the field names in your sheet (case and space)
This example uses the express framework:
const app = express();
// Parse JSON bodies for this app.
app.use(express.json());
app.post('/', function(request, response){
data = request.body;
// debug purpose: show in console raw data received
console.log("Request received: \n"+JSON.stringify(data, null, 2));
// NOTE:
// orca system fields start with ___
// you can access the value of each field using the field name (data.Name, data.Barcode, data.Location)
const name = data.Name
//validation example
if(name.length > 20){
//return json error message
response.json({
"title": "Invalid Name",
"message": "Name cannot contain more than 20 characters",
}).send();
return;
}
//return HTTP Status 200 with no body
response.status(200).send();
});
app.listen(3000, () => console.log('Example app is listening on port 3000.'));
To expose the server securely from localhost and test it easily against the real Orca Cloud environment you can use Secure Tunnels. Take a look at Ngrok or Cloudflare.
ngrok http 5000
If you run into any issues not listed here, please open a ticket.
- orca-validation-dotnet
- orca-validation-python
- orca-validation-go
- orca-validation-java
- orca-validation-php
- orca-validation-node
For change-log, check releases.
© Orca Scan, the Barcode Scanner app for iOS and Android