# How to run a custom javascript script on startup of node red

**URL:** <https://discourse.nodered.org/t/how-to-run-a-custom-javascript-script-on-startup-of-node-red/52429>\
**Category:** General\
**Created:** [19 October 2021 16:38 UTC](https://discourse.nodered.org/t/how-to-run-a-custom-javascript-script-on-startup-of-node-red/52429 "2021-10-19T16:38:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnrich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tnrich/32/47942_2.png) [@tnrich](https://discourse.nodered.org/u/tnrich)\
**Post date:** [19 October 2021 16:38 UTC](https://discourse.nodered.org/t/how-to-run-a-custom-javascript-script-on-startup-of-node-red/52429/1 "2021-10-19T16:38:46Z")

</div>

Hey there,

I'm looking to customize the UI and possibly hide or inject certain element on the node-red editor. Is there a way to have a javascript file be called on startup of node-red and run in the window?

Seems like this would probably be a useful feature.

Here's how I'm starting node red (v2) right now.

```auto
const express = require("express");
const RED = require("node-red");
const path = require("path");
const jwt = require("jsonwebtoken");
const dbConfig = require("./pg-db.config");
const app = express();
const { PostgresNodeREDAdapter } = require("./PostgresNodeREDAdapter");
const logDebug = require("./logDebug");
app.enable("trust proxy");

const port = process.env.PORT || 6700;
const authSecret = process.env.TG_AUTH_SECRET;

app.use("/", express.static("public"));

console.info(`Starting up Node-RED on port ${port}`);

if (process.env.DEBUG_NODE_RED) {
  console.info(`Node-RED debug logging enabled`);
}

const server = app.listen(port, () =>
  console.info(`Node-RED server listening on port ${port}!`)
);

const userDir = path.resolve(__dirname, "../node-red-data");

const settings = {
  editorTheme: {
    theme: "midnight-red",
    codeEditor: {
      lib: "monaco",
      options: {
        theme: "vs-dark"
      }
    }
  },
  nrlint: require("./.nrlintrc.js"),
  httpAdminRoot: "/node-red-editor",
  httpNodeRoot: "/node-red-api",
  userDir,
  dbConfig,
  autoInstallModules: true,
  storageModule: new PostgresNodeREDAdapter(),
  adminAuth: {
...etc
  },
  functionGlobalContext: {
   ...etc
  } // enables global context
};

RED.init(server, settings);

app.use(settings.httpAdminRoot, RED.httpAdmin);
app.use(settings.httpNodeRoot, RED.httpNode);

// Start the runtime
RED.start();

```

Thanks in advance!  
-Thomas

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 October 2021 16:45 UTC](https://discourse.nodered.org/t/how-to-run-a-custom-javascript-script-on-startup-of-node-red/52429/2 "2021-10-19T16:45:52Z")

</div>

Not quite sure what you mean. That looks like js to me. So can’t you do it from there ?

---

<div class="post-metadata">

**Author:** ![tnrich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tnrich/32/47942_2.png) [@tnrich](https://discourse.nodered.org/u/tnrich)\
**Post date:** [19 October 2021 17:07 UTC](https://discourse.nodered.org/t/how-to-run-a-custom-javascript-script-on-startup-of-node-red/52429/3 "2021-10-19T17:07:46Z")

</div>

That is the server js code that serves the node red app via express. What I want to do is run a js script in the node red app in the browser upon start up

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [19 October 2021 17:10 UTC](https://discourse.nodered.org/t/how-to-run-a-custom-javascript-script-on-startup-of-node-red/52429/4 "2021-10-19T17:10:59Z")

</div>

Under `editorTheme` in your settings object, you can set `page.scripts` to point at a custom JavaScript file you'd like the editor to load: [Configuration : Node-RED](https://nodered.org/docs/user-guide/runtime/configuration#editor-themes)

You provide the path of the file on the local filesystem and the runtime takes care of serving it to the editor.

---

<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:** [2 November 2021 17:11 UTC](https://discourse.nodered.org/t/how-to-run-a-custom-javascript-script-on-startup-of-node-red/52429/5 "2021-11-02T17:11:23Z")

</div>

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