0

I am developing a full MEAN stack web application. At this moment my app is listening to localhost:3000. Is there any way in js that I can set a URL like www.something.com and it will redirect to localhost:3000. Below is a sample server code that I have implemented.

#!/usr/bin/env node
var debug = require('debug')('passport-mongo');
var app = require('./app');


app.set('port', process.env.PORT || 3000);


var server = app.listen(app.get('port'), function() {
   debug('Express server listening on port ' + server.address().port);
});
3
  • 1
    No. You will need a domain name. Nothing to do with your app. Commented Jan 15, 2018 at 13:20
  • I cannot even locally on my computer do something like this? Just for example writing as url myApp, not even with www and i want this from browser to redirect to localhost:3000 Commented Jan 15, 2018 at 13:22
  • well you could try specifying the hostname of your computer instead of localhost. Depends if the webserver is listening for that or not. But if you're just testing locally, who cares? Commented Jan 15, 2018 at 13:26

2 Answers 2

1

No.

If you could, it would be like being about to cause anybody trying to visit or deliver a letter to an arbitrary address (e.g. the Ministry of Defence) to arrive at your house instead.

If you want to direct www.example.com to your server, then you need to control www.example.com and configure its DNS servers to point www.example.com to your server's IP address.


If you want to direct port 80 (the default for an HTTP request) to port 3000 on your system, then you'll need to do that at the system level. (e.g. with IP Tables).

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to do this locally only on your PC, you can edit your C:\Windows\System32\drivers\etc\hosts file.

Replace the following line:

127.0.0.1 localhost

With the line:

127.0.0.1 www.example.com

If you want to access port 3000 you would have to type www.example.com:3000 in your browser.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.