Node Red NodeJS Embedding

Hi Guys, would like to ask. I am currently having some problem when launching the nodeJS with the node-red. I just try the example the code from the node-red website, but it seems to getting the error of web socket problem. I am not sure if whether I need to setup manually or is there something I need to do?

I am running it on local host:
image

image

My Node JS Code:

var http = require("http");
var express = require("express");
var RED = require("node-red");

// Create an Express app
var app = express();

// 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 = {
  httpAdminRoot: "/red",
  httpNodeRoot: "/api",
  userDir: "/nodered-stuff/nol/.nodered/",
  functionGlobalContext: {}, // enables global context
  editorTheme: {
    page: {
      title: "GDESK Node-RED",
    },
    header: {
      title: "GDESK Node-RED",
    },
  },
};

// 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();

Are you running behind any kind of proxy like nginx? If so, you need to configure it to allow websocket requests through.

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