Issue with remove file

Hello,

I’ve got some issue for remove file with Code node.

VAR : NODE_FUNCTION_ALLOW_BUILTIN well setted

Code :

const fs = require('fs');
var stdout = ""

const path = "G:/library/userpref.blend";
if(fs.existsSync(path)){
  fs.unlink(path)
  stdout = "File remove"
}else{
  stdout = "File not found"
}

return [{json : { "stdout": stdout}}];

error :

ERROR: Unknown error [line 6]

TypeError [ERR_INVALID_ARG_TYPE]: The "cb" argument must be of type function. Received undefined
    at makeCallback (node:fs:195:3)
    at Object.unlink (node:fs:1764:14)
    at ReadOnlyHandler.apply (C:\Users\brutus\AppData\Roaming\npm\node_modules\n8n\node_modules\vm2\lib/bridge.js:485:11)
    at C:\Users\brutus\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-nodes-base\dist\nodes\Code:6:6
    at C:\Users\brutus\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-nodes-base\dist\nodes\Code:13:2
    at VM2 Wrapper.apply (C:\Users\brutus\AppData\Roaming\npm\node_modules\n8n\node_modules\vm2\lib\bridge.js:485:11)
    at Sandbox.run (C:\Users\brutus\AppData\Roaming\npm\node_modules\n8n\node_modules\vm2\lib\nodevm.js:426:23)
    at Sandbox.runCodeAllItems (C:\Users\brutus\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-nodes-base\dist\nodes\Code\Sandbox.js:53:42)
    at Sandbox.runCode (C:\Users\brutus\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-nodes-base\dist\nodes\Code\Sandbox.js:30:62)
    at Object.execute (C:\Users\brutus\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-nodes-base\dist\nodes\Code\Code.node.js:75:39)

Have you got an idea ?

regards,

  • n8n version: 0.202.1
  • Database you’re using (default: SQLite):
  • Running n8n via npm

Hello,

no one has encountered this problem?

regards,

Sorry for the noise…I was not well awake
it was simple missing call back

do not,

if(fs.existsSync(path)){
  fs.unlink(path)
  ...

but do

fs.unlink(deleteFile, function (err) {
  if (err) {
   ...
1 Like

Hi @Jeremy_Bepoix, glad to hear you figured it out, many thanks for confirming!