local-routes

Package that allows access to the localhost using directory-based routes simply and quickly.

Usage no npm install needed!

<script type="module">
  import localRoutes from 'https://cdn.skypack.dev/local-routes';
</script>

README


local-routes

npm installnfo

Table of contents

About

local-routes is a package that allows access to the localhost using directory-based routes simply and quickly.

Installation

Node.js v14.16.1 or newer is recommended.

Install: npm install local-routes

Example usage

Example directory

.
├──index.js
├──package.json
└──/white-cat/
     ├──image.png
     ├──index.html
     └──/directory-a/
          └──file.html

index.js

const localhost = require('local-routes');

const routesPath = __dirname + '/white-cat';
const routeDirnamePath = __dirname;

localhost.initServer(routesPath, routeDirnamePath);

In this case, the files will be available in the browser at:

  • http://localhost:3000/white-cat/image.png
  • http://localhost:3000/white-cat/index.html
  • http://localhost:3000/white-cat/directory-a/file.html


Please note that http://localhost:3000 will not be available, if you want to add a file as the main one, do this:

const localhost = require('local-routes');

const routesPath = __dirname + '/white-cat';
const routeDirnamePath = __dirname;
const mainFilePath = __dirname + '/white-cat/index.html';

localhost.initServer(routesPath, routeDirnamePath, mainFilePath);

Links

Help

If you are experiencing problems, or you just need a nudge in the right direction, please do not hesitate to create a New Issue on Github repository.