or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

application.mdcli.mdfunction-nodes.mdhttp-services.mdindex.mdnode-development.mdruntime.mdutilities.md

application.mddocs/

0

# Application Management

1

2

Core application lifecycle management for embedding Node-RED in other applications. These functions control the initialization, startup, and shutdown of the complete Node-RED system including runtime and editor components.

3

4

## Capabilities

5

6

### Initialize Application

7

8

Initialize the Node-RED application with HTTP server and configuration settings.

9

10

```javascript { .api }

11

/**

12

* Initialize the Node-RED application

13

* @param httpServer - Optional HTTP server instance. If not provided, settings object is first parameter

14

* @param userSettings - Configuration settings object

15

*/

16

function init(httpServer?: http.Server, userSettings: UserSettings): void;

17

```

18

19

**Usage Examples:**

20

21

```javascript

22

const RED = require("node-red");

23

const http = require("http");

24

25

// Option 1: With existing HTTP server

26

const server = http.createServer();

27

RED.init(server, {

28

userDir: "./node-red-data",

29

httpAdminRoot: "/admin",

30

httpNodeRoot: "/api"

31

});

32

33

// Option 2: With settings only (Node-RED manages server)

34

RED.init({

35

uiPort: 1880,

36

userDir: "./node-red-data"

37

});

38

```

39

40

### Start Application

41

42

Start the Node-RED runtime and editor services. Must be called after `init()`.

43

44

```javascript { .api }

45

/**

46

* Start the Node-RED runtime and editor

47

* @returns Promise that resolves when startup is complete

48

*/

49

function start(): Promise<void>;

50

```

51

52

**Usage Examples:**

53

54

```javascript

55

RED.start().then(() => {

56

console.log("Node-RED started successfully");

57

}).catch(err => {

58

console.error("Failed to start Node-RED:", err);

59

});

60

61

// With async/await

62

try {

63

await RED.start();

64

console.log("Node-RED started");

65

} catch (err) {

66

console.error("Startup failed:", err);

67

}

68

```

69

70

### Stop Application

71

72

Stop the Node-RED runtime and editor. Should be called before process exit for clean shutdown.

73

74

```javascript { .api }

75

/**

76

* Stop the Node-RED runtime and editor

77

* @returns Promise that resolves when shutdown is complete

78

*/

79

function stop(): Promise<void>;

80

```

81

82

**Usage Examples:**

83

84

```javascript

85

// Graceful shutdown

86

process.on('SIGINT', async () => {

87

console.log('Shutting down Node-RED...');

88

try {

89

await RED.stop();

90

console.log('Node-RED stopped');

91

process.exit(0);

92

} catch (err) {

93

console.error('Error during shutdown:', err);

94

process.exit(1);

95

}

96

});

97

```

98

99

### Access HTTP Services

100

101

Access the Express applications for custom integration.

102

103

```javascript { .api }

104

/**

105

* Express application for the editor interface

106

*/

107

const httpAdmin: express.Application;

108

109

/**

110

* Express application for HTTP nodes

111

*/

112

const httpNode: express.Application;

113

114

/**

115

* HTTP server instance used by Node-RED

116

*/

117

const server: http.Server;

118

```

119

120

**Usage Examples:**

121

122

```javascript

123

const express = require("express");

124

const app = express();

125

126

// Start Node-RED

127

await RED.start();

128

129

// Integrate editor into existing app

130

app.use("/red", RED.httpAdmin);

131

132

// Integrate HTTP nodes into existing app

133

app.use("/api", RED.httpNode);

134

135

// Add custom routes

136

app.get("/status", (req, res) => {

137

res.json({

138

version: RED.version,

139

uptime: process.uptime()

140

});

141

});

142

```

143

144

### Version Information

145

146

Get the current Node-RED version.

147

148

```javascript { .api }

149

/**

150

* Get the Node-RED version string

151

*/

152

const version: string;

153

```

154

155

## Settings Configuration

156

157

### Core Settings

158

159

```javascript { .api }

160

interface UserSettings {

161

/** Port for the editor UI (default: 1880) */

162

uiPort?: number;

163

/** Host for the editor UI (default: '0.0.0.0') */

164

uiHost?: string;

165

/** Root path for admin API (default: '/') */

166

httpAdminRoot?: string;

167

/** Root path for HTTP nodes (default: '/') */

168

httpNodeRoot?: string;

169

/** User directory for flows and settings (default: ~/.node-red) */

170

userDir?: string;

171

/** Flow file name (default: 'flows.json') */

172

flowFile?: string;

173

/** Secret for encrypting credentials */

174

credentialSecret?: string;

175

/** CORS settings for HTTP nodes */

176

httpNodeCors?: {

177

origin?: string | string[];

178

credentials?: boolean;

179

};

180

}

181

```

182

183

### Advanced Settings

184

185

```javascript { .api }

186

interface AdvancedSettings {

187

/** Logging configuration */

188

logging?: {

189

console?: {

190

level: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';

191

metrics?: boolean;

192

audit?: boolean;

193

};

194

file?: {

195

level: string;

196

filename: string;

197

maxFiles?: number;

198

maxSize?: string;

199

};

200

};

201

/** Context storage configuration */

202

contextStorage?: {

203

default?: string;

204

stores?: {

205

[storeName: string]: {

206

module: string;

207

config?: object;

208

};

209

};

210

};

211

/** Global context for Function nodes */

212

functionGlobalContext?: object;

213

/** Export global context keys to Function nodes */

214

exportGlobalContextKeys?: boolean;

215

/** External modules configuration */

216

externalModules?: {

217

modules?: {

218

[moduleName: string]: {

219

module: string;

220

config?: object;

221

};

222

};

223

};

224

}

225

```

226

227

**Usage Examples:**

228

229

```javascript

230

RED.init({

231

uiPort: 1880,

232

userDir: "./node-red-data",

233

httpAdminRoot: "/admin",

234

httpNodeRoot: "/api",

235

flowFile: "flows.json",

236

credentialSecret: "my-secret-key",

237

functionGlobalContext: {

238

util: require("util"),

239

moment: require("moment")

240

},

241

logging: {

242

console: {

243

level: "info",

244

metrics: false,

245

audit: false

246

}

247

},

248

contextStorage: {

249

default: "memoryOnly",

250

stores: {

251

memoryOnly: { module: "memory" },

252

file: { module: "localfilesystem" }

253

}

254

}

255

});

256

```