Last part, let's make Express answer with a list of people.
// back/src/index.jsimportappfrom'./app'importinitializeDatabasefrom'./db'conststart=async()=>{constcontroller=awaitinitializeDatabase()app.get('/',(req,res)=>res.send("ok"));app.get('/contacts/list',async(req,res)=>{constcontacts_list=awaitcontroller.getContactsList()res.send(contacts_list)})app.listen(8080,()=>console.log('server listening on port 8080'))}start();
We now have two routes in our express app. / leads to "ok", and /contacts/list gives us a list of contacts.
Great! Moving on to linkage with the front-end now. We're almost done with our setup
PART II - Step 7: Access the Back-End from the Front-End
Let's go back to our front end. We need to be able to access this data.
In a first instance, let's keep it simple. We're simply going to query the back-end, and log the answer
Move into front/src, open index.js, and write in it, anywhere:
run the root npm start, to start the back and front. Go to http://localhost:3000, and check the console. You should see the contacts in your log. Ok great!
Let's use that in React now. Remove the lines above, we don't need them anymore