Coder Social home page Coder Social logo

express-react's Introduction

Express & React:
How express and react are connected??
make a react app of name client or anyother name and a file of server.
Now we know we can start react app by writing npm start and server file by node server.js
But to run them concurrently on same command we have to do some changing i.e:
Install concurrently library:
npm install -g concurrently(It helps to run multiple commands concurrently)

    "client":"npm start --prefix client",
    "server":"nodemon server.js",
Add this to the scripts of ur pacakage.json of ur main folder
now we can run react app by running npm run client and server by npm run server
But to run them concurrently we have to make another script:
"dev":"concurrently \"npm run server\" \"npm run client\" "
now we just have to run npm run dev
Make sure u have different localhost for like 3001 if react app is running on 3000

Now u want to send data from server to client.How u will u do as they r runnig on different local host
example if i want to get data data from localhost:3001/api/user(my server)
and if i write axios.get('/api/user') then it will go to localhost:3000/api/user

To resolve this we will go to pkg.json file of client and proxy the server
  "proxy":"http://localhost:3001"

express-react's People

Contributors

usmannarshad avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.