To render out the response from an Express Node app in TypeScript, first you need to create a React component. In the component, make an HTTP request to the Node app using Axios. Once the request succeeds, you can set state with the result.
Here's an example App.tsx
file:
index.ts490 chars25 lines
Assuming your Node app is listening on port 3000, the Axios request will be sent to http://localhost:3000/api/data
. You'll need to make sure your Node app has a GET /api/data
route defined that returns a JSON response with a message
property.
Lastly, make sure you have the necessary dependencies installed in your project:
index.ts31 chars2 lines
And make sure your TS config is configured to allow for imports without extensions:
index.ts322 chars16 lines
gistlibby LogSnag