> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Running an HTTP server for testing

> How to install Node.js http-server and serve static HTML files locally so you can follow PlayFab authentication tutorials for Facebook, Google, or Twitch.

In some scenarios, you may need to run a local HTTP server for test purposes. For example, if you're following our tutorials for setting up PlayFab authentication using [Facebook and HTML5](/services/playfab/identity/player-identity/platform-specific-authentication/facebook-html5), [Google and HTML5](/services/playfab/identity/player-identity/platform-specific-authentication/google-html5), or [Twitch and HTML5](/services/playfab/identity/player-identity/platform-specific-authentication/twitch-html5), and you don't have a remote server with a domain, you may find this tutorial useful.

## Prerequisites

* Installed [Node.JS](https://nodejs.org/en/)

## Installing HTTP server using npm

Run the command line/terminal on your system (it doesn't matter which directory you're currently in).

Execute `npm install -g http-server`. Once npm finishes, you have the tiny HTTP-server installed. That's it.

## Serving files

Create a new folder on your system from where you want to serve your static files. There are no specific restrictions for path on Windows.

On macOS, you may want to check for access on the folder. Inside of the newly created folder, create a file called **index.html**.

Fill the file with the content provided below.

```html theme={null}
<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>My Page</title>
</head>

<body>
 <p>Hello world!</p>
</body>
</html>
```

Run the **command line/terminal** and cd to the folder with your **index.html** file, then:

1. Execute **http-server**.
2. **HTTP-server** will start serving files from your current directory.
3. It will also print all the **IP** endpoints that the server is listening for.
4. Use one of them to reach your web-server through the browser.
5. Observe your page being loaded.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/serving-files-with-http-server.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=d01d646ad860fd92c2917526c08f06f5" alt="Serving files with the http-server command" width="1225" height="602" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/serving-files-with-http-server.png" />

You can optionally specify a port to run the server on.

* **Example**: Execute `http-server -p 80` to run your server on **port 80**. If a port is occupied, you'll have to find what application is using this port and shut it down before you attempt to run the HTTP server again.

### Serving files with a custom domain name

When testing different SDKs, for example, [Google](/services/playfab/identity/player-identity/platform-specific-authentication/google-html5) or [Facebook](/services/playfab/identity/player-identity/platform-specific-authentication/facebook-html5), you'll notice that some services can only be configured with a certain valid domain name.

For instance, they don't accept a plain IP address + port. Certain services use such a configuration to ensure that your browser fetches your code from a specific, secure domain.

They also often use this configuration to ensure that a user can only log into your application from your domain, and that nobody else can fake it and steal user data.

<Note>
  While this is an important and useful security restriction, it may produce complications when trying to locally test your code.
</Note>

If you run your server on Port 80, and your use-case is simple enough, you can utilize the HOSTS file on your operating system to access your HTTP server through a valid domain name.

The HOSTS file is a special file available on both Windows and macOS. It allows you to override certain domain names with custom endpoints. Schematically, the HOSTS file looks like this:

```cmd theme={null}
IP_ADDRESS_1 DOMAIN_NAME_1
IP_ADDRESS_2 DOMAIN_NAME_2
IP_ADDRESS_3 DOMAIN_NAME_3

# This is comment
# IP_ADDRESS_4 DOMAIN_NAME_4 <- this entry is commented out and is inactive
...
```

Each line represents exactly *one* entry. When you try to reach `DOMAIN_NAME_1`, your browser directs your request to `IP_ADDRESS_1`.

The same applies for *each* entry in the HOSTS file. In the preceding example, entry number `4` starts with `#`. This is a syntax for comment.

By *commenting* out certain entries you may disable them, without necessarily removing them from the HOSTS file.

`playfab.example` is a valid domain name, but it's unlikely that your browser will reach any website with it. By adding the following entry to your HOSTS file, you'll be able to reach your local HTTP server with that domain name.

```cmd theme={null}
127.0.0.1 playfab.example
```

<Note>
  If you are using a port other than 80, you will need to add the port that was created when the local server started (such as port 8080) to the end of the URL (`<playfab.example:8080>`)
</Note>

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/http-server-hello-world.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=cdcc112f35435bdb52872c45a6c4627a" alt="HTTP server - Hello World" width="660" height="173" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/http-server-hello-world.png" />

On Windows OS, the HOSTS file is normally located at:

`C:\Windows\System32\drivers\etc\hosts`.

On macOS, the HOSTS file is normally located at:

`/private/etc/hosts`.

<Warning>
  When entering your domain name in your browser address bar, always make sure to include the schema: `<http://playfab.example>`.
</Warning>


## Related topics

- [Server Anonymous Login Authentication](/services/playfab/identity/player-identity/platform-specific-authentication/anonymous-login.md)
- [Setting up PlayFab authentication using Google and HTML5](/services/playfab/identity/player-identity/platform-specific-authentication/google-html5.md)
- [Setting up PlayFab authentication using Twitch and HTML5](/services/playfab/identity/player-identity/platform-specific-authentication/twitch-html5.md)
- [Set up Sign In with Battle.net for PlayFab](/services/playfab/identity/player-identity/platform-specific-authentication/battlenet-login.md)
- [Setting up PlayFab authentication using Facebook and HTML5](/services/playfab/identity/player-identity/platform-specific-authentication/facebook-html5.md)
