Hi, I'm trying to embed node red in my nodejs project referring to Embedding into an existing app : Node-RED.
but it try to build executable for my project I am not able to
my package. json file
{
"name": "nodered",
"version": "1.0.0",
"main": "index.cjs",
"bin": {
"nodered-app": "index.cjs"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "pkg --target=latest-win-x64 -o \"./dist/service.exe\" index.cjs"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"axios": "^1.7.8",
"express": "^4.21.1",
"node-red": "^4.0.5"
},
"devDependencies": {
"esbuild": "^0.24.0"
}
}
index.cjs
const http = require('http');
const express = require('express');
const RED = require('node-red');
const app = express();
const server = http.createServer(app);
// Middleware for parsing JSON request bodies
app.use(express.json());
// Define Node-RED settings
const settings = {
httpAdminRoot: "/red", // Node-RED editor available at /red
httpNodeRoot: "/api", // Node-RED HTTP nodes available at /api
userDir: "./node-red-data", // Directory for Node-RED flow configurations
functionGlobalContext: {}, // Global context for Function nodes
};
// Initialize Node-RED
RED.init(server, settings);
// Serve the Node-RED editor
app.use(settings.httpAdminRoot, RED.httpAdmin);
// Serve the Node-RED HTTP nodes
app.use(settings.httpNodeRoot, RED.httpNode);
// Define custom APIs
app.get('/custom/status', (req, res) => {
res.json({ status: "Node-RED is running", uptime: process.uptime() });
});
app.post('/custom/add-flow', async (req, res) => {
const flow = req.body; // Expect flow data in the request body
try {
// Example of adding a flow via Node-RED Admin API
const adminApi = `http://localhost:1880/red/flows`;
const response = await fetch(adminApi, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ flows: flow })
});
if (response.ok) {
res.json({ message: "Flow added successfully" });
} else {
res.status(500).json({ error: "Failed to add flow" });
}
} catch (error) {
console.error("Error adding flow:", error);
res.status(500).json({ error: "Internal server error" });
}
});
// Start the server
server.listen(1880, () => {
console.log("Server running at http://localhost:1880");
console.log("Node-RED editor available at http://localhost:1880/red");
});
// Start the Node-RED runtime
RED.start();
and if try to exeute npm run build
I get following error
> pkg@5.8.1
(node:6400) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
> Fetching base Node.js binaries to PKG_CACHE_PATH
fetched-v16.16.0-win-x64 [====================] 100%
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\axios.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\utils.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\bind.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\Axios.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\mergeConfig.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\defaults\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\formDataToJSON.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\cancel\CanceledError.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\cancel\CancelToken.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\cancel\isCancel.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\env\data.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\toFormData.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\AxiosError.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\spread.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\isAxiosError.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\AxiosHeaders.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\adapters\adapters.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\HttpStatusCode.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\buildURL.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\InterceptorManager.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\dispatchRequest.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\buildFullPath.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\validator.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\defaults\transitional.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\toURLEncodedForm.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\platform\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\platform\node\classes\FormData.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\parseHeaders.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\adapters\http.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\adapters\xhr.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\adapters\fetch.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\form-data-encoder\lib\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\lowercase-keys\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\p-cancelable\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\responselike\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\AxiosURLSearchParams.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\transformData.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\isAbsoluteURL.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\combineURLs.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\platform\node\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\platform\common\utils.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\core\settle.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\fromDataURI.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\AxiosTransformStream.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\formDataToStream.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\readBlob.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\ZlibHeaderTransformStream.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\callbackify.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\progressEventReducer.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\parseProtocol.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\resolveConfig.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\composeSignals.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\trackStream.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\mimic-response\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\normalize-url\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\platform\node\classes\URLSearchParams.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\speedometer.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\throttle.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\isURLSameOrigin.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\axios\lib\helpers\cookies.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\string-width\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\@isaacs\cliui\node_modules\strip-ansi\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\wrap-ansi\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\string-width\node_modules\strip-ansi\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\@isaacs\cliui\node_modules\ansi-regex\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\ansi-styles\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\wrap-ansi\node_modules\strip-ansi\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\string-width\node_modules\ansi-regex\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\nodered\node_modules\wrap-ansi\node_modules\ansi-regex\index.js
can anyone help me with it ?