Project Loading Forever

Hello,

I’m having an issue where my glitch project is still loading forever, even after using the code from the default server.js file to solve the issue. I’m using the brain.js package, and as soon as I paste the code from that, the issue returns.

const express = require("express");
const app = express();
const brain = require ("brain.js")
const net = new brain.recurrent.LSTM();

net.train([
  { input: 'I feel great about the world!', output: 'happy' },
  { input: 'The world is a terrible place!', output: 'sad' },
]);

const output = net.run('I feel great about the world!'); // 'happy'

// as soon as i remove the code above, the issue goes away

/////////////////////////////////////////////////////////////////////////////////

// our default array of dreams
const dreams = [
  "Find and count some sheep",
  "Climb a really tall mountain",
  "Wash the dishes"
];

// make all the files in 'public' available
// https://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));

// https://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
  response.sendFile(__dirname + "/views/index.html");
});

// send the default array of dreams to the webpage
app.get("/dreams", (request, response) => {
  // express helps us take JS objects and send them as JSON
  response.json(dreams);
});

// listen for requests :)
const listener = app.listen(process.env.PORT, () => {
  console.log("Your app is listening on port " + listener.address().port);
});

Hey!

The brain.js docs make me wonder whether the training step is actually what takes a long time, but you don’t know it until you try run:…https://github.com/BrainJS/brain.js#training-options

You could try to constrain the training time like this:

const data = [
  { input: 'I feel great about the world!', output: 'happy' },
  { input: 'The world is a terrible place!', output: 'sad' },
];

net.train(data, {
  timeout: 5000, // the max number of milliseconds to train for
});

See if that helps.

Also, currently, your output doesn’t go anywhere. You could log it with console.log to see it in the Glitch project log as your project loads, or else you could make a new Express endpoint that returns the value of output (this is left as an exercise for the reader).

HTH

Hmm. The issue persists even after adding the new couple of lines with the timeout.

const brain = require ("brain.js")
const net = new brain.recurrent.LSTM();

const data = [
  { input: 'I feel great about the world!', output: 1 },
  { input: 'The world is a terrible place!', output: 0 },
];

net.train(data, {
  timeout: 5000, // the max number of milliseconds to train for
});

const output = net.run("I feel great about the world!")

console.log(output)


// our default array of dreams
const dreams = [
  "Find and count some sheep",
  "Climb a really tall mountain",
  "Wash the dishes"
];

// make all the files in 'public' available
// https://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));

// https://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
  response.sendFile(__dirname + "/views/index.html");
});

// send the default array of dreams to the webpage
app.get("/dreams", (request, response) => {
  // express helps us take JS objects and send them as JSON
  response.json(dreams);
});

// listen for requests :)
const listener = app.listen(process.env.PORT, () => {
  console.log("Your app is listening on port " + listener.address().port);
});

Sorry buddy! ¯\_(ツ)_/¯

I’d recommend trying it on your local machine instead of Glitch to see if you can figure out whether it’s taking a really long time or there’s another problem.