html-express

1.0.7 • Public • Published

How to install

npm i html-express

OR

yarn add html-express

How to use

1. Import the client function

const { client } = require("html-express")

2. Run it

client()

The client function takes an argument. An object with the next properties:

  • htmlPath - a string with the path of the directory where you find the index.html file, the default is "build" and you don't have to change it if the build directory is in the same folder with the js, where you call the function

  • port - a number which indicates the port where your server will run, the default is process.env.PORT or 3000

  • routers - other routers that you may want to add, especially for backend

Reqs property

If you want to combine the backend and frontend in only one server, you can use the routers property. It is an array of objects which take 2 properties:

  • path - the path of the router. ex: /api

  • router - the router that you want to attribute to the path. ex: require("./router")

Practical example

const { client } = require("html-express")

client({
  port: 8000,
  htmlPath: "dist",
  routers: [{
    path: "/api",
    router: require("router")
  }]
})

Run the server with node [path]/[file name] and check on the browser the url displayed on the console.

If you used the upper code the url should be: http://localhost:8000

Made by Marius Atasiei

Package Sidebar

Install

npm i html-express

Weekly Downloads

2

Version

1.0.7

License

ISC

Unpacked Size

2.51 kB

Total Files

4

Last publish

Collaborators

  • mariusatasiei