Laraib Zafar
Laraib Zafar

Reputation: 1

Can't Connect Client(ReactJS) and Backend(NodeJS) both working on different Ports on the Localhost

I've worked with ReactJS before but this is my first time messing around with NodeJS This is the ReactJS code where I'm trying to send the Video File to the server

This is the NodeJS file I'm simply trying to print something to the console but nothing works

This is definitely a dumb question I know, it's just I don't know what I'm doing wrong, it's my first time messing around with Backend stuff.

Upvotes: 0

Views: 27

Answers (1)

Renato Silva
Renato Silva

Reputation: 65

Have you added the CORS module to your backend so it accepts request from a different URL?

Install cors with 'npm install cors' then add the following to your backend server.js (or index.js or whatever file is creating the routes):

import cors from 'cors';
import express from 'express';

const app = express()
app.use(cors)

The app.use has to come before your routes

Upvotes: 2

Related Questions