In this article we will cover how to create a React application using React-Router for routing and an Express backend. We will then deploy it to He...
For further actions, you may consider blocking this person and/or reporting abuse
are you interested to form a team for reactjs freelance projects ? i'm looking for react developers everyway
Hi,
how are you doing
i am interested to be a part of experienced developers to enhance my skills
i am a software engineer having 5 years or working experience in mobile web and desktop apps development
looking forward to hearing from you soon
best regards
devasad
Hi Ahmed,
I am interested in undertaking React projects. I am fairly new to it, but I am confident I can contribute in a React team. Feel free to contact me if you want to continue our conversation.
I am really interested. Is this still up?
Interested in this Ahmed
Hey Ahemd,
Lemme know if this is still open, I'm interested
Hi Ahmed, I am very much interested in React projects. You can contact me anytime
Hi,
First of all thanks for the article, it is a great help.:D
I have done all the things you mentioned and I am facing 2 issues,
1) res.json() in List.js gives an error that '<' token is found i.e. syntax error but I didn't use the method just for sake to deploy on heroku.
2) I deployed on heroku succesfully but when I open my app on heroku I am shown "Not Found" error (most probably 404).
Can you help?
Be sure to remove the git folder (generated by Create React App) in the client directory. Doing so will allow Heroku to build your React app and fix the "Not Found" error.
i have the same issue with deploying to heroku.
I'm running into the same problem now - did you ever happen to find a solution to this?
What is the purpose of
npm install --only=dev
in the heroku-postbuild script for building the client? I tried removing that bit and it still worked.At the time of writing, I believe that Heroku installed only the production dependencies by default, ignoring the development dependencies under devDependencies.
npm install --only=dev
had to be added for the project to build correctly. I think this default behavior has been changed so it may no longer be needed!Hey, Nicolas thank you for this awesome tutorial, it's was very helpful to understand the connection between both layers.
I create my own project structure using KeystoneJS and react and was great! I'm using in my personal projects right now.
Hello Nicolas,
First of all, thanks a lot for your work. Anyway, I have an issue with your project. If you run the server and then:
The App will be deployed in localhost:8080 and works. But, if I access to the list and reload the page:
That's because the HTTP static server doesn't found the
list
file.I'm pretty sure that if you access directly to: yourHerokuServer/list you will find the same problem.
There is a little workaround: copy the index.html to list and mark its content type as text/html, but I strongly believe that we need another solution to this issue :/
Thanks for your time.
UPDATE: Same question resolved here: stackoverflow.com/questions/279283...
Error when typing "npm start" in home directory
thats what it says
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! react-express-ex@1.0.0 start:
node ../index.js | react-scripts start
npm ERR! Exit status 255
npm ERR!
npm ERR! Failed at the react-express-ex@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
any solution to this problem
I have the same problem. The router entry in package.json doesn't seem to be working. the /api calls still go to the react app on port 3000.
Here is my package.json file:
{
"name": "ubwo",
"version": "0.1.0",
"private": true,
"proxy":"localhost:5000/",
"dependencies": {
"react": "16.8.6",
"react-dom": "16.8.6",
"react-redux": "7.1.0",
"react-router": "5.0.1",
"react-router-dom": "5.0.1",
"react-scripts": "3.0.1",
"redux": "4.0.1",
"redux-thunk": "2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"resolutions": {
"browserslist": "4.6.2",
"caniuse-lite": "1.0.30000974"
}
}
Any ideas what I can try to get this working?
You could try using
http://localhost:5000
instead of what you have now (localhost:5000/
). (Actually, having written that I'm not sure that IS the problem...this board seems to be reformatting URLs that aren't backtick-ed.)Just FYI: I started from zero with this tutorial a few hours ago and got everything 100% working (including a Heroku deploy). So any bugs you might encounter are probably not in the posted code.
Hi Nicolas,
Thanks for this article. It was really useful for me to get started with a React/Express project.
I would like to ask you if there is a way to deploy by uploading a build folder manually to a server. I am a React beginner so apologies for any mistake in my question.
Kind regards,
João
I'm getting this error when I try to start the react app:
Failed to compile
./src/index.js
Module not found: Can't resolve 'react-router-dom' in 'C:\Users...'
I followed the tutorial. Am I missing something?
in client folder do npm install react-router-dom. It wasn't mentioned in the tutorial
So I would need to run npm start for both express and the client? Is the proxy you added just for local development? How would I deploy this test code of yours to production
You would need to run npm start for both locally. It works in production as well, I'll add a section on deployment tonight.
For running locally from your ./client folder, you can modify your package.json script to start both at the same time:
And when you C to terminate batch job, it will terminate both front and back localhosts.
Thanks. I would guess you would want to compile the code in the client folder so yeah, would love to read about that process
I've added a short section, I hope that everything is clear
Yes this makes sense. Your creating a Node Heroku setup and it will run that. Thanks
I have a followed your approach but i am facing a issue.
I have one home page route at express from which i want to pass through a middle-ware function isResturantOpen when ever the user visits the react app.
app.get('/',passportConfig.isResturantOpen, (req,res) =>{
console.log('reached')
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
but when i ever i tries to visit my website home of react.js at this url
localhost:5000/ then my above route does not work
but all the routes are being going to this main route.
app.get('*', (req,res) =>{
console.log(req)
// console.log(res)
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
so now if i want to apply some different express.js middle ware functions on each different routes then how can i do this..?
Can you please help me on this.?
path.join
should be passed two arguments. It's redundant the way you're using it in your main express file.Hi Nicolas, I had follow your steps to do a easier version. But When I deploy to heroku, it's just present "Not Found", could you please advice any solution for current heroku deployment? Below provided client side package json
Hi Nicholas, I had found out the reason that my page is showing "Not Found". May I know is there anyway to push the client folder to heroku? Because I cloned the whole file and found out my client folder is totally empty.
The proxy will work in local machine only, in heroku the port might be different isn't it?
I wasted my 4 hours in looking for this way. Thanku for this article
Super helpful guide! Straight forward setup and introduced me to some technologies and concepts.
Hi Nicolas,
Thanks for the article. It seems that when I make the fetch request for the list at ('api/getList') I get a 404 error. It seems that the request is ignoring the proxy and trying to go to 'localhost:300/api/getList' rather than 'localhost:5000/api/getList'.
If I fully define the path in the fetch request ie fetch('localhost:5000/api/getList') then I get an error:
Access to fetch at 'localhost:5000/api/getList' from origin 'localhost:3000' has been blocked by CORS policy: blah blah blah
I understand that one should never really unblock CORS. So my question is, how to I make get requests to my server? And what is the point in the 'proxy' if it does not solve this problem?
try adding cors headers if you're facing the cors related problem
Rad walkthrough. Thanks! :)
Great article, Nicolas! It really helped me with a project I was hitting the wall with. Cheers.
Great article. Helped me a lot.
Keep up the good work.
Nicolas this is wonderful explanation. Keeping everything simple! Thank you!
Awesome .best totorial I have ever came onto in devto
Great tutorial, thanks! Helped me a lot with setting up a project and saved a lot of headache:)
Great post. Thanks!
The only guide I found that worked right away, thanks broski
While doing this there is a Problem i get when i manually input the routes like \list i get error of cannot GET \list . How to solve this ??.
Thank you so much for this! I have been looking for a solution for a few hours
How can we publish in plesk? We have a shared server with Windows - I think with IIS - and node.js (if necessary)... Can you help us?
Is it possible to deploy this on Apache?
Thanks a lot. It solved my problem with the BrowserRouter of React.js.
The trick for me was proxy in manifest.json
hi
How to fix this error?
thepracticaldev.s3.amazonaws.com/i...