Single page react app using node api gives 404 error on Production server


I have a validation form on React but on clicking submit m getting “404 Error”. It works perfect on local machine. //from app.js

handleSubmit = async e => { e.preventDefault(); const response = await fetch(‘/api/emailVerifier’, { method: ‘POST’, body: this.state, headers: { ‘Content-Type’: ‘application/json’, },

  //body: JSON.stringify({ post: }),

const body = await response.text();

this.setState({ responseToPost: body });

}; //from server.js‘/api/emailVerifier’, async (req, res) => { console.log(req.body); const emailValidator = new EmailValidator(); const { wellFormed, validDomain, validMailbox } = await emailValidator.verify(; res.send(

`response received , welllformed = ${wellFormed}, validDomain = ${validDomain}, validMailbox = ${validMailbox}`,

); }); i have installed my my validator on server using npm i add deep-email-validator --save

My Directory on server has

asset-manifest.json index.html manifest.json package.json static build logo192.png node_modules robots.txt favicon.ico logo512.png package-lock.json server.js

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Thanks my problem is fixed. I created separate project for react and node and tried deploying using app platform. It worked. Earlier I was having single project fro both of them

Have you wired your backend server correctly? From the looks of it, you are attempting to serve the client and server from the same host? If so, are you pointing the server to your build correctly? Here’s a reference from the create-react-app documentation

My hunch is that your client app is the only thing deployed and your server is not running on the same host or is not setup correctly. You want your server to power the client and send the build back on non-api paths as shown in the example at the link above.