# Reading a .mdb file

**URL:** <https://discourse.nodered.org/t/reading-a-mdb-file/65659>\
**Category:** Industrial\
**Created:** [26 July 2022 23:54 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659 "2022-07-26T23:54:58Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [26 July 2022 23:54 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/1 "2022-07-26T23:54:58Z")

</div>

Hi,

I have an equipment that writes to an .mdb file. I believe that this is a type of database.

Can you suggest any node or any other way that I can read the latest entry in the file.

Thank you

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 July 2022 00:04 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/2 "2022-07-27T00:04:56Z")

</div>

MDB files come from Microsoft Access. You can get a copy by subscribing to Microsoft Office 365.

Alternatively, Libre Office should let you open them as should Kexi.

You should also be able to get ODBC or JDBC drivers to open them.

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [27 July 2022 00:44 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/3 "2022-07-27T00:44:09Z")

</div>

Hi,

I want to read the data directly in to node red. Is that possible.?

If so, can you share me any links/manual on how to set it up

thank you

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [27 July 2022 03:29 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/4 "2022-07-27T03:29:52Z")

</div>

There doesnt seem to be a node-red node to access Access 🤪  
since its not very commonly used and there are more modern dbs as a replacement but ..  
doing a quick search on the internet reveals that there is an npm package called [mdb-reader](https://www.npmjs.com/package/mdb-reader) that can read those files.

So by using a Node-red Function and its [functionExternalModules](https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option) option and adapting the code example from the link :

```auto
[{"id":"f58e0f8db2538520","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":3580,"wires":[["89431c89cd3fbf86"]]},{"id":"89431c89cd3fbf86","type":"function","z":"54efb553244c241f","name":"MDB Reader","func":"const { readFileSync } = fs;\nconst MDBReader = mdb;\n\nconst buffer = readFileSync(\"C:/share/PetStore2002.mdb\");\nconst reader = new MDBReader(buffer);\n\nconst tables = reader.getTableNames();\nconst table = reader.getTable(\"Animal\");\nconst columns = table.getColumnNames();\nconst data = table.getData();\nconst lastEntry = data[data.length - 1]\n\nmsg.payload = { tables, table, columns, data, lastEntry };\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"mdb","module":"mdb-reader"},{"var":"fs","module":"fs"}],"x":490,"y":3580,"wires":[["32f5e6abb8d5ca44"]]},{"id":"32f5e6abb8d5ca44","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":3580,"wires":[]}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/43fdcb26f1b3de060a995eecec8eb1822fe8116a.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f486d6ca8d9e1e03470eb02a11dc8d05188fdb98.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 July 2022 09:59 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/5 "2022-07-27T09:59:14Z")

</div>

There are also ODBC and JDBC nodes.

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [28 July 2022 01:01 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/6 "2022-07-28T01:01:47Z")

</div>

Hi,

I was trying your suggestion but I got stuck editing the settings.js. Im able to install the mdb-reader.

 ![function globalcontext](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/4157e665f88211bf9ed8fdf492d5d0559eb94dff.png)  
 ![NodeRedError](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/652aee5f5c97dc272c49ab2cc34835f8b7c43892.png)  
the line "fs:require('fs')," works but I think the line "mdb-reader:require('mdb-reader')" because Im not able to start node red and it throws an error at this line.

For the fs though,Im able to see it in node red function node. but I did not install anything for the fs. Do I need to install anything?

I have actually never edited this portion of the settings.js file before .Can you please assist me further on this.

thank you

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [28 July 2022 01:53 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/7 "2022-07-28T01:53:11Z")

</div>

What version of Node-red are you running ?

Comment out the `fs` and `mdb-reader` lines from the **functionGlobalContext** section .. you dont need them.

The new feature of `functionExternalModules: true` would be enough if you are running a quite recent version of Node-red and the modules should auto-install when you deploy the flow i shared.

ps. make sure you restart NR after the settings.js changes

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [28 July 2022 02:35 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/8 "2022-07-28T02:35:27Z")

</div>

![noderedversion](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0b37807010458a0ba9d430213a17709c5c9e636c.png)  
hi,  
the version used is v2.0.6

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [28 July 2022 02:40 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/9 "2022-07-28T02:40:57Z")

</div>

> [@dinesh](#):
>
> the version used is v2.0.6

ok .. thats fine .. the `functionExternalModules` feature was introduced in version 1.3.0

`Error: port in use` most probably you are running Node-red as a service and you tried to run it twice ?

Try from the terminal  
`node-red-stop`  
and then  
`node-red-start`

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [28 July 2022 03:21 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/10 "2022-07-28T03:21:25Z")

</div>

Hi,  
The node red was already.I just rerun it just to get the node red version.  
I have reboot/power recycle my device. Node Red is running fine

But the modules are not visible in the function node setup.By default the functionExternalModules is already set to true. I tried searching online and it mentions to add the line in functionglobalcontext. However, it doesnt seem to work for mdb reader.

Any idea what could have gone wrong?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [28 July 2022 17:02 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/11 "2022-07-28T17:02:23Z")

</div>

> [@dinesh](#):
>
> I tried searching online and it mentions to add the line in functionglobalcontext.

As i mentioned in my previous posts, **functionGlobalContext** was an older option .. it can still work but there is no need to use that way of using external modules because the newer feature **functionExternalModules** was introduced in Node-red version 1.3.0. You have v2.0.6 so that's fine.

> [@dinesh](#):
>
> By default the functionExternalModules is already set to true

great

> [@dinesh](#):
>
> But the modules are not visible in the function node setup

thats strange .. you imported the flow that i shared above and you dont see the modules listed there ?  
Can you show us a screenshot ?  
Can you add them manually ? - although you wouldnt need to

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [29 July 2022 00:19 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/12 "2022-07-29T00:19:35Z")

</div>

hi,  
actually if I import your nodes, the modules are visible in the function node setup.

But if I don't import, it doesn't show the modules automatically in the function node setup.

Let me try import, and see if I can read my mdb data..

thank you

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [29 July 2022 00:35 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/13 "2022-07-29T00:35:52Z")

</div>

Hi,

I tried. it gives error message for the modules.

 ![mdberr](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b90b00460a7dcf239739c0770ec225f3c7396883.png)  
I have included my nodes as a reference  
[flows (5).json](https://discourse.nodered.org/uploads/short-url/q1gEKB7Br2YGO5ceTi378HUTuCr.json) (1.3 KB)

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [29 July 2022 00:45 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/14 "2022-07-29T00:45:48Z")

</div>

Is this because Im using nodeJs v12.?

if so is there a work around?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [29 July 2022 00:59 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/15 "2022-07-29T00:59:22Z")

</div>

> [@dinesh](#):
>
> Is this because Im using nodeJs v12.?

must be ..  
it mentions on the npm site of the **mdb-reader** module that the supported version is node 14 and 16  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61f2d79f75c65d3015bcba2f03025ec69ef1c3ec.png)

What OS are you running Node-red on ? is it Linux based ?  
Did you install node-red using the official bash script ? ([link](https://nodered.org/docs/getting-started/raspberrypi))

If yes .. you can add `--node16` to the script to update your Node-red to the latest version 3.0.1 and also nodejs to v16.

Like this:

`bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node16`

ps. its good practice to make a backup of your flows first

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [29 July 2022 02:31 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/16 "2022-07-29T02:31:25Z")

</div>

Actually the device I'm using is a Siemens gateway device, IOT2050. In the Siemens website, an image file is provided. Upon loading it, all the software including NodeRed is installed automatically.  
Current OS version used is linux Debian 11.

Let me try your suggestion and see what happens.

Thank you

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [29 July 2022 02:36 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/17 "2022-07-29T02:36:10Z")

</div>

> [@dinesh](#):
>
> Let me try your suggestion and see what happens.

I think its better **not** to !! better consult with Siemens support how to update you device properly .. cause it may have things that depend on specific versions and may break functionality

**[EDIT]**  
that said .. there is a video of a person upgrading the IOT2050 with that command

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3a8e6ca81a4f75346c035b8fbd4f002aa598b69.jpeg "IOT2050 - 04 Node-RED version 2 Upgrade") ](https://www.youtube.com/watch?v=tE_XU3oBouY)

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [6 August 2022 03:30 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/18 "2022-08-06T03:30:38Z")

</div>

Hi,

Upon upgrading the nodeJs to v16 and node red to v3.0.2(Exactly as per the youtube video), I am able to successfully read the mdb file using sample code provided.

Thank you very much. This helped a lot.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 August 2022 03:31 UTC](https://discourse.nodered.org/t/reading-a-mdb-file/65659/19 "2022-08-20T03:31:21Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
