skip to Main Content

i am a beginner (i don’t even know how to ask the question correctly) and i try creating my first clone website as a project with the help of youtube tutorial and everything went well but i have one issue with the url…so when the person that i watch run his code it shows as http://127.0.0.1:5000 (which i know is the localhost address) but when i run it keep showing http://localhost:5000 so can anyone tell me how do i set mine to show like this http://127.0.0.1:5000

i want my url to show http://127.0.0.1:5000 instead of http://localhost:5000

Edit: there’s a lot of answers thaks to everyone but there seem to be some confusion and i don’t really know how to answer them (i’m sorry i will become better) so i’ll just put a picture i it…also i am using npmenter image description here

4

Answers


  1. It’s simple the person you are watching has there own HTTP WEB SERVER and that’s why there project is running at Localhost address , and if you also want to do the same thing you would need to program the server yourself or use a http server software for running your website on Localhost address.

    I hope this helps you!

    Login or Signup to reply.
  2. Open your package.json file in your react project and find scripts section in it. Under the scripts section you need to modify the start section value to react-scripts start --host 127.0.0.1. Finally, your package.json scripts section will look like the below with your other configuration:

    "scripts": {
      "start": "react-scripts start --host 127.0.0.1",
      ...
    }
    

    Make sure to save your changes and proceed with npm start. Now your client-side application will be available to access via http://127.0.0.1:5000

    Login or Signup to reply.
  3. Your question is not well defined unless you state how you run your web app.

    If Create React App is used, as assumed by Selaka Nanayakkara’s answer, you can also use a HOST environment variable.

    Login or Signup to reply.
  4. Presumption

    Its kinda hard to understand what your trying to imply, but from what i’m seeing you’re wanting to show your local host-name IP (127.0.0.1 in this case) rather than localhost in the search bar

    Solution

    Based on the above –

    # 1 Create a .env.local file in the main directory (not in any subfolders)

    # 2

    Within that file have the following

    HOST=127.0.0.1
    

    # 3

    Run yarn or npm once more and it should work!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search