Having troubles with client in index.js

image

Code Line:

const client = require("./public/client");

Client code:

// define variables that reference elements on our page
const dreamsList = document.getElementById('dreams');
const dreamsForm = document.forms[0];
const dreamInput = dreamsForm.elements['dream'];

Hi @Cannonski13, welcome!

Your snippet of the error doesn’t show us the actual syntax error, it would be a little bit above the bit you snipped… can you share that?

Anyway, perhaps you need to include the file extension when require-ing client.js ?

Let us know :slight_smile:

Sorry about that
image

Ok, are you doing that ‘require client’ from the backend Node.js code? The client.js is only meant to be run in the browser, where the document object exists. It looks like it’s running on the server, so it can’t find document because there isn’t a web page to work with :slight_smile:

1 Like

Wait heres the code for Index.js

const http = require('http');
const express = require('express');
const app = express();
const db = require("quick.db");
const fs = require("fs");
const client = require("./public/client");
const Discord = require("discord.js");

and here is client.js

// define variables that reference elements on our page
const dreamsList = document.getElementById('dreams');
const dreamsForm = document.forms[0];
const dreamInput = dreamsForm.elements['dream'];

Cool, so, you don’t need to require client from the server, it won’t work. Take out that line and see how it goes?

Was there a reason you added that? Just wondering :slight_smile:

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