Create a barcode API with javascript
I’m using Visual Studio code on a MacBook Pro M1, the following sample code in JavaScript uses a third-party library to generate a Code 128 barcode and return it as a PNG image.
The example is based on bwip-js available on github: https://github.com/metafloor/bwip-js
Note! The purpose of this guide is to show how to create a simple web server with node.js to generate barcodes as images, if you are to use bwip-js in production you should add security to the code for the web server.
If you don’t have visual studio code, you can downlaod it for free here
If you have never used node.js before, you can find it good example to get up and running here
Download node.js: https://nodejs.dev/en/download/
Start Visual Studio code
- Select ‘Open folder’ and create a new folder called ‘create-barcode’ to store your project.
2. Open a terminal either by tool in menu ‘Terminal – new terminal’ or by ‘Launchpad’ – Terminal.
(Make sure you are in the right folder by typing pwd and press enter, otherwise navigate to the right path where you stored the ‘create-barcode’ folder)
3. Type ‘Yarn init’ and press enter to initialize a new project and create package.json
4. Type yarn add nodemon http bwip-js and press enter.
Your package.json should look like this:

5. Create a new file called index.js and copy in the code:
6. Open package.json and create a new section called scripts like this:
7. Save all files
8. In Terminal: ‘yarn start’ and press enter. It should look like this:
Use postman to try it out
Click the New button and select HTTP.
Create a barcode api with javascript – Copy example URL and paste in input after GET
Example:
Create a barcode api with javascript – Click Send
You should get this result:
Eller testa i en webbläsare
- Öppna en webbläsare och klistra in
Not everyone can code their own systems – there are ready-made solutions.
Although this is a good example of how you can create a barcode API with javascript and then build the functionality into your existing reporting systems or apps, not everyone has the knowledge, desire or time to create and maintain an in-house solution. Therefore, there is software that makes it easy to automatically create labels, barcodes, etc. without the knowledge or the need to operate systems. Cloudlabel does all this and more, book a demo to talk with us about how you can easily move forward with barcodes and traceability