How to Find and Configure the IIS Root Directory (localhost) for JavaScript File Access


2 views

When working with Windows IIS (Internet Information Services), the default installation typically places web server components in these locations:

Main IIS components: %SystemRoot%\System32\inetsrv
Default web root: C:\inetpub\wwwroot

The wwwroot directory serves as the primary location where your JavaScript files should be placed for localhost access. However, IIS allows configuration of multiple root directories through virtual directories.

To verify your current IIS root directory:

  1. Open IIS Manager (search for "Internet Information Services (IIS) Manager" in Start menu)
  2. Expand the server node in the Connections panel
  3. Select SitesDefault Web Site
  4. In the Actions panel, click Basic Settings

The physical path shown here is your current root directory for http://localhost.

For a typical JavaScript project structure:

C:\inetpub\wwwroot\myproject\
├── index.html
├── js/
│   ├── app.js
│   └── utils.js
└── data/
    └── config.json

You would access this via: http://localhost/myproject/index.html

If you prefer to keep files elsewhere but make them accessible via localhost:

// PowerShell commands to create virtual directory
Import-Module WebAdministration
New-WebVirtualDirectory -Site "Default Web Site" -Name "myapp" -PhysicalPath "D:\projects\javascript-app"

This would map http://localhost/myapp to your project in D:\projects\javascript-app.

With files in the IIS root, you can safely use relative paths:

// In your JavaScript file
fetch('/data/config.json')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

When serving files through IIS for JavaScript access:

  • Configure proper MIME types (especially for JSON, XML, etc.)
  • Set appropriate directory browsing permissions
  • Enable CORS if needed by adding to web.config:
<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

If files aren't accessible via localhost:

  • Check that the IIS service is running
  • Verify file permissions in the root directory
  • Ensure the Default Web Site is started in IIS Manager
  • Check for port conflicts (default is port 80)

When working with Windows IIS, the default root directory for http://localhost is typically:

C:\inetpub\wwwroot\

This is where IIS serves files by default for the Default Web Site. You can verify this by:

  1. Opening IIS Manager (press Win+R, type inetmgr)
  2. Navigate to "Sites" > "Default Web Site"
  3. Click "Basic Settings" in the right-hand Actions pane

While inetpub\wwwroot is standard, the location might differ if:

  • IIS was installed with custom settings
  • The default website was modified
  • You're working with a virtual directory

To programmatically find the root path using PowerShell:

Import-Module WebAdministration
(Get-ItemProperty 'IIS:\Sites\Default Web Site').physicalPath

For your JavaScript display to access local files through IIS:

  1. Place your files in the root directory (or subfolder)
  2. Configure proper MIME types if serving unusual file formats
  3. Set appropriate permissions (right-click folder > Properties > Security)

Example folder structure:

wwwroot/
├── index.html
├── js/
│   └── display.js
└── data/
    └── products.json

If you can't use the default root, create a virtual directory pointing to your files:

# PowerShell script to create virtual directory
Add-WebVirtualDirectory -Site "Default Web Site" -Name "storefront" -PhysicalPath "C:\path\to\your\files"

Then access via: http://localhost/storefront

  • 403 Forbidden: Check directory permissions (IIS_IUSRS needs read access)
  • 404 Not Found: Verify file paths and URL bindings
  • MIME type errors: Add missing types in IIS Manager

For JSON files, ensure this MIME type exists:
Extension: .json
MIME Type: application/json