![]() We then create a method to handle a GET request for /api/getList that will send a json response with a list of items. We call express() in order to create our express application, denoted by the object app. Res.sendFile(path.join(_dirname+'/client/build/index.html')) Ĭonsole.log('App is listening on port ' + port) ![]() Handles any requests that don't match the ones above An api endpoint that returns a short list of items Serve the static files from the React appĪpp.use(express.static(path.join(_dirname, 'client/build'))) Install the express package: npm add expressĬreate a file named index.js and enter the following code, this will serve as a most basic express app. Initialize the project with npm: npm init -y Here we will call ours react-express-example. To start we will need to create a parent directory, which can be named anything you want. In order to begin setting up our app, both node.js and npm need to have been installed. The source code for this application can be found here. If you have a different method or if I have made any mistakes, feel free to let me know. There are several ways to accomplish this goal but I have covered a very simple method that I am most familiar with. It may also offer help to those who are new to React. This tutorial offers a simple way to set up an API that can be quickly updated and tested while creating a React application. In this article we will cover how to create a React application using React-Router for routing and an Express backend.
0 Comments
Leave a Reply. |