Home > Net >  React not recognizing Express
React not recognizing Express

Time:03-16

In my jsx file, I have the following:

var express = require('express');
var myExpress = express();
var http = require('http');
var app = http.createServer(myExpress);
var { Server } = require("socket.io");
var myio = new Server(app);

However, the browser says "Uncaught TypeError: express is not a function"

I have tried importing express with an import statement, as well as making my project a module in my package.json. What is weird is that when I use the same code in a regular js file in the same folder, it works perfectly well. This code was the code in every single one of the tutorials, so I am at a loss. Thank you.

CodePudding user response:

Express is node framework you can't use it in react. I think you need https://v5.reactrouter.com/web/guides/quick-start

CodePudding user response:

Express is for setting up server and providing http endpoint for your frontend app like React, and with the data, you can render UI dynamically. At this point, you should firstly develop a good understanding with both front and back end, try not worry about the require/import syntax. Just make things work

  • Related