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

**URL:** <https://discourse.nodered.org/t/when-starting-via-the-command-line-and-via-the-api-if-there-is-no-flowdata-directory-the-api-startup-method-will-report-an-error/90049>\
**Category:** General\
**Created:** [8 August 2024 07:47 UTC](https://discourse.nodered.org/t/when-starting-via-the-command-line-and-via-the-api-if-there-is-no-flowdata-directory-the-api-startup-method-will-report-an-error/90049 "2024-08-08T07:47:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [8 August 2024 07:47 UTC](https://discourse.nodered.org/t/when-starting-via-the-command-line-and-via-the-api-if-there-is-no-flowdata-directory-the-api-startup-method-will-report-an-error/90049/1 "2024-08-08T07:47:11Z")

</div>

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

```auto
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

```auto
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

```

---

<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:** [6 November 2024 07:48 UTC](https://discourse.nodered.org/t/when-starting-via-the-command-line-and-via-the-api-if-there-is-no-flowdata-directory-the-api-startup-method-will-report-an-error/90049/2 "2024-11-06T07:48:00Z")

</div>

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