When starting via the command line and via the API, if there is no `flowData` directory, the API startup method will report an error

When starting via the command line and via the API, if there is no flowData directory, the API startup method will report an error

When I start nodered via the command line npx node-red -s settings.js, if there is no flowData directory in the current directory, one will be generated and the project can start normally.

But when I start via the API, RED.init() and RED.start(), flowData will be automatically generated if there is no flowData in the current directory, but the generated .config.runtime.json and .config.runtime.json.backup content seems incorrect, which will cause an error

This is the directory tree

flowData
┣ lib
┃ ┗ flows
┣ node_modules
┣ .config.nodes.json
┣ .config.nodes.json.backup
┣ .config.runtime.json // cant delete this
┣ .config.runtime.json.backup // cant delete this
┣ .config.users.json
┣ .config.users.json.backup
┗ package.json

app.js file,Start through node app.js, error

var http = require("http");
var express = require("express");
var RED = require("node-red");
var config = require("./settings");

// Create an Express app
var app = express();
const cors = require("cors");

app.use(cors());
app.use(express.json());

// Add a simple route for static content served from 'public'
app.use("/", express.static("public"));

// Create a server
var server = http.createServer(app);

// Create the settings object - see default settings.js file for other options
var settings = {
  ...config,
  httpAdminRoot: "/red",
  httpNodeRoot: "/api",
  userDir: __dirname + "/flowData",
  functionGlobalContext: {}, // enables global context
};

// Initialise the runtime with a server and settings
RED.init(server, settings);

// Serve the editor UI from /red
app.use(settings.httpAdminRoot, RED.httpAdmin);

// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot, RED.httpNode);

server.listen(8000);

// Start the runtime
RED.start()

Console error message

PS D:\node-red-project> npm run serve

> red-project@1.0.0 serve
> node app.js

8 Aug 16:00:24 - [info] 

Welcome to Node-RED
===================

8 Aug 16:00:24 - [info] Node-RED version: v3.1.9-git
8 Aug 16:00:24 - [info] Node.js  version: v18.18.0
8 Aug 16:00:24 - [info] Windows_NT 10.0.22631 x64 LE
8 Aug 16:00:25 - [info] Loading palette nodes
8 Aug 16:00:25 - [info] Context store  : 'default' [module=memory]
8 Aug 16:00:25 - [info] User directory : D:\node-red-project/flowData
8 Aug 16:00:25 - [warn] Projects disabled : editorTheme.projects.enabled=false
8 Aug 16:00:25 - [info] Flows file     : D:\node-red-project\flowData\flows.json        
8 Aug 16:00:25 - [info] Creating new flow file
8 Aug 16:00:25 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

D:\node-red-project\node_modules\@node-red\runtime\lib\flows\index.js:527
        config.flows.forEach(function(n) {
               ^

TypeError: Cannot read properties of null (reading 'flows')
    at Object.checkTypeInUse (D:\node-red-project\node_modules\@node-red\runtime\lib\flows\index.js:527:16)
    at Object.disableNode (D:\node-red-project\node_modules\@node-red\runtime\lib\nodes\index.js:144:11)
    at D:\node-red-project\app.js:108:13

Node.js v18.18.0

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