-2

I want to open new tab in react and node app. I did window.open() and it worked on client side but its giving issue on server side that means it works on port 3000 and gives error Cannot GET "some/url" when ran on port 7000. How to solve this issue ? Thanks in advance !

Komal Thamke
  • 193
  • 1
  • 2
  • 11
  • in simple words, how will i be able to make window.open() work on server side ? – Komal Thamke Aug 26 '19 at 06:53
  • [Duplicate](https://stackoverflow.com/questions/11355366/how-to-redirect-users-browser-url-to-a-different-page-in-nodejs). [here is your answer](https://stackoverflow.com/questions/11355366/how-to-redirect-users-browser-url-to-a-different-page-in-nodejs#answer-11355594) – Arseniy-II Aug 26 '19 at 07:21
  • Possible duplicate of [How to redirect user's browser URL to a different page in Nodejs?](https://stackoverflow.com/questions/11355366/how-to-redirect-users-browser-url-to-a-different-page-in-nodejs) – Arseniy-II Aug 26 '19 at 07:21

1 Answers1

1

You can open the URL in a new window using nodeJS using the default browser.

var url = 'http://localhost:3000';
var start = (process.platform == 'darwin'? 'open': process.platform == 'win32'? 'start': 'xdg-open');
require('child_process').exec(start + ' ' + url);

nodeJS is a backend and reactJS is a frontend you have to understand there will be more options to play with browser functions using front-end. If you have doubt comment it :)

You can use npm package called opn click here

Pardeep
  • 2,153
  • 1
  • 17
  • 37
  • window.open is not working in production when i build the app – Komal Thamke Aug 26 '19 at 08:31
  • Yes, it will not work on the production. Will you please show your code? – Pardeep Aug 26 '19 at 09:38
  • client side code is window.open(/lab/${param}/case/${caseid}/something, "_blank"); server-side creted a route app.route("/lab/:param/case/:case_id/something") – Komal Thamke Aug 27 '19 at 11:05
  • I think you have to send something from backend to front end as an API hit ajax and check it then use window.open or you can push your code on GitHub so I can easily understand what you want to do exactly. – Pardeep Aug 27 '19 at 12:26