Flow stops when using FILE node

Hello all,

I have tried to set a flow that writes three diferent files in a local folder. I am running it in Localhost with Docker. When I try to run it, the flow has some strange behaviours as soon as I introduce the FILE node, such as:

  • Debug nodes are not printing anything
  • the flow does not seem to keep runing after the first or second FILE node.

My question is, do I need to somehow close the file I wrote in? if so, how can I do it?

Just to give an example, in one flow I need to write twice in the same file (with some nodes in between) and, second time does not do anything.

I am using v2.0.5 and cannot update yet...

Thanks a lot :slight_smile:

Welcome to th forum Alberto!

It would help to see the flow. Please export it and attach it to a reply.

Hi, in order to make code readable and importable it is important to surround your code with three backticks
```
like this
```

See this post for more details - How to share code or flow json

Yes this is a problem of the file Node but I have a workaround. The file remains really open when you specify the filename and path in the file node.

It is also specified in the help of the node. If you want that the file node closes the file after each writing, you should not specify the filename in the node. Use msg.filename instead and the file will be automatically closed after each writing.

1 Like

Hello again. Sorry for not attaching the flow (amateur's mistake hahaha).

I am currently using the filename as a var for the nodes and still not working properly :frowning:

I have also a really strange behaviour when using Global variables: I set a global variable as a flag, and everything goes OK when I do not have a FILE node in my flow. When the flow has this node, the variables disappear... :worried:

thanks a lot for your help!

[
    {
        "id": "542c869f1c352732",
        "type": "change",
        "z": "842eff3d74e57d5a",
        "name": "selectInfo",
        "rules": [
            {
                "t": "set",
                "p": "rowCount",
                "pt": "msg",
                "to": "payload.rowCount",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.rows",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1260,
        "y": 3060,
        "wires": [
            [
                "f17c260415820045"
            ]
        ]
    },
    {
        "id": "21a3a3a05a70e660",
        "type": "postgrestor",
        "z": "842eff3d74e57d5a",
        "name": "getIncentivesEXT1",
        "query": "SELECT *FROM basededatos.beneficiarios;",
        "postgresDB": "b18a371b44992e25",
        "output": true,
        "outputs": 1,
        "x": 1070,
        "y": 3060,
        "wires": [
            [
                "542c869f1c352732"
            ]
        ]
    },
    {
        "id": "f17c260415820045",
        "type": "csv",
        "z": "842eff3d74e57d5a",
        "name": "",
        "sep": ",",
        "hdrin": "",
        "hdrout": "all",
        "multi": "one",
        "ret": "\\n",
        "temp": "",
        "skip": "0",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 1450,
        "y": 3060,
        "wires": [
            [
                "65e884b101c40785"
            ]
        ]
    },
    {
        "id": "f27a0c87cfc1efb5",
        "type": "change",
        "z": "842eff3d74e57d5a",
        "name": "getReqParams",
        "rules": [
            {
                "t": "set",
                "p": "repData.schema",
                "pt": "msg",
                "to": "pinc",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "domain",
                "pt": "msg",
                "to": "config.domain",
                "tot": "global"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 800,
        "y": 3100,
        "wires": [
            [
                "21a3a3a05a70e660"
            ]
        ]
    },
    {
        "id": "65e884b101c40785",
        "type": "file",
        "z": "842eff3d74e57d5a",
        "name": "",
        "filename": "",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "utf8",
        "x": 1610,
        "y": 3060,
        "wires": [
            [
                "0645bd9a445147ae"
            ]
        ]
    },
    {
        "id": "8c246be2afeceb63",
        "type": "change",
        "z": "842eff3d74e57d5a",
        "name": "setAdHoc",
        "rules": [
            {
                "t": "set",
                "p": "busyFlag",
                "pt": "global",
                "to": "busy",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "isAdHoc",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 3060,
        "wires": [
            [
                "f27a0c87cfc1efb5"
            ]
        ]
    },
    {
        "id": "0645bd9a445147ae",
        "type": "change",
        "z": "842eff3d74e57d5a",
        "name": "setReady",
        "rules": [
            {
                "t": "set",
                "p": "busyFlag",
                "pt": "global",
                "to": "ready",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "ready",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "filename",
                "pt": "msg",
                "to": "./files/busy/status.txt",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1780,
        "y": 3060,
        "wires": [
            [
                "7ee79ad9123dab7f"
            ]
        ]
    },
    {
        "id": "93837e0327a0025b",
        "type": "function",
        "z": "842eff3d74e57d5a",
        "name": "namingADHOC",
        "func": "var ts = new Date();\nvar dateTo = new Date();\nvar thisMonth = dateTo.getMonth() + 1;\nvar thisYear = dateTo.getFullYear();\nvar thisTime = (\"00\" + ts.getHours()).slice(-2) + \"\" + (\"00\" + ts.getMinutes()).slice(-2) + \"\" + (\"00\" +ts.getSeconds()).slice(-2);\nmsg.repData = {};\n\nvar dateFrom = \"01-01-\" + thisYear;\nmsg.repData.taxedDateFrom = dateFrom;\n\n//next lines get the report until \"yesterday\"\ndateTo.setDate(dateTo.getDate() - 1);\ndateTo.setHours(0, 0, 0, 0);\nvar dayTo = dateTo.getDate();\nvar monthTo = dateTo.getMonth() + 1;\nvar yearTo = dateTo.getFullYear();\nthisMonth = (\"00\" + thisMonth).slice(-2);\ndateTo = yearTo + \"-\" + monthTo + \"-\" + dayTo;\n\nmsg.repData.taxedDateTo = dateTo;\n\nmsg.filename = \"./files/adHoc\" + yearTo + monthTo + dayTo + \"-\" + thisTime + \".csv\";\n\nmsg.payload = \"busy\";\n\nreturn [msg, null];",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 620,
        "y": 3060,
        "wires": [
            [
                "8c246be2afeceb63"
            ]
        ]
    },
    {
        "id": "7ee79ad9123dab7f",
        "type": "file",
        "z": "842eff3d74e57d5a",
        "name": "removeBusy",
        "filename": "",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "delete",
        "encoding": "none",
        "x": 1930,
        "y": 3060,
        "wires": [
            []
        ]
    },
    {
        "id": "46309b6a126853e3",
        "type": "file",
        "z": "842eff3d74e57d5a",
        "name": "createBusy",
        "filename": "",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "utf8",
        "x": 410,
        "y": 3080,
        "wires": [
            [
                "93837e0327a0025b"
            ]
        ]
    },
    {
        "id": "44bd59bd0c3ff464",
        "type": "function",
        "z": "842eff3d74e57d5a",
        "name": "nameForBusy",
        "func": "\nmsg.filename = \"./files/busy/status.txt\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 3040,
        "wires": [
            [
                "46309b6a126853e3"
            ]
        ]
    },
    {
        "id": "4a03a538e9ee5ea4",
        "type": "http in",
        "z": "842eff3d74e57d5a",
        "name": "POST /files/creation",
        "url": "/files/creation",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 130,
        "y": 3060,
        "wires": [
            [
                "13a4cd17fd0b9c54",
                "44bd59bd0c3ff464"
            ]
        ]
    },
    {
        "id": "13a4cd17fd0b9c54",
        "type": "http response",
        "z": "842eff3d74e57d5a",
        "name": "started",
        "statusCode": "204",
        "headers": {
            "content-type": "application/json"
        },
        "x": 150,
        "y": 3100,
        "wires": []
    },
    {
        "id": "b18a371b44992e25",
        "type": "postgresDB",
        "name": "pincDatabase",
        "host": "config.dBHostName",
        "hostFieldType": "global",
        "port": "config.dbPort",
        "portFieldType": "global",
        "database": "config.dbDatabase",
        "databaseFieldType": "global",
        "ssl": "false",
        "sslFieldType": "bool",
        "max": "10",
        "maxFieldType": "num",
        "min": "1",
        "minFieldType": "num",
        "idle": "5000",
        "idleFieldType": "num",
        "user": "config.dBUser",
        "userFieldType": "global",
        "password": "config.dbPwd",
        "passwordFieldType": "global"
    }
]

When you say 'the variables disappear' what do you mean?
What variables?
Where do they dissapear?
and what do you mean by 'when I do not have a FILE node in my flow' Are you removing the node?
Are you using persistant storage for your context variables?
(here is something to read A guide to understanding 'Persistent Context')

I dont know why you use the file busy file at all. Why you use not only flow or global variables.

However I do not use the permanent context - and therefore I cannot say, if the file nodes do interfere with the file nodes, but normally it have no influence. May be you should put some delay nodes in your flow and check the context.

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