I'm building a JS project to learn new skills, and I'm having trouble delineating between the client-side code and the server-side code. The current setup is a node app with ExpressJS as a dependency.
When I run npm run build && npm run dev
, the base html/css is served as expected, but I get an error in my console from the express script.
main.fb6bbcaf.js:116 Uncaught TypeError: Cannot read property 'prototype' of undefined at Object.parcelRequire.node_modules/express/lib/response.js.safe-buffer (response.js:42) at newRequire (main.fb6bbcaf.js:47) at localRequire (main.fb6bbcaf.js:53) at Object.parcelRequire.node_modules/express/lib/express.js.body-parser (express.js:22) at newRequire (main.fb6bbcaf.js:47) at localRequire (main.fb6bbcaf.js:53) at Object.parcelRequire.node_modules/express/index.js../lib/express (index.js:11) at newRequire (main.fb6bbcaf.js:47) at localRequire (main.fb6bbcaf.js:53) at Object.parcelRequire.js/main.js.express (main.js:1)
For reference, I'm still trying to get the example code from the express documentation to run, so my whole main.js
file looks like this:
const express = require('express');
const app = express();
const port = 1234;
app.get('/hello', (req, res) => res.send('Hello World!'));
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
I found a person with a similar issue HERE, but what doesn't click for me (and what I can't seem to find a proper question for) is how to separate the client-side and server-side code in my project. I get the feeling that I'm trying to use express in code that's being served to the client, but I don't know where else to put it.
Is there a best-practice location for server-side code in a project that uses both node and express?