lite-web-server
The npm package to create simple web server.
This will load files from ./public/
directory if it's not specified.
Install
npm i lite-web-server
Example
This server will load files from ./public/
directory.
var { WebServer } = require("lite-web-server")
var server = new WebServer()
server.start()
If you want to specify the directory to load a file, use the code below.
var { WebServer } = require("lite-web-server")
var server = new WebServer({
dir: "./public_html/"
})
server.start()
API
WebServer(options)
Constructor
options
port (optional)
Type: Number
Default: 3000
new WebServer({
port: 3000
})
directory (optional)
Type: String
Default: ./public/
The directory to load the file.
new WebServer({
dir: "./public_html/"
})
notfound (optional)
Type: String
(html code)
Default: 404 Not Found
new WebServer({
notfound: "<center><h1>File was not found on this server.</h1></center>"
})
GetContentType(name)
Function
name
Type: String
Type a filename to get http header content-type.
var { GetContentType } = require("lite-web-server")
var htmlname = "example.html"
var contenttype = GetContentType(htmlname)
console.log(contenttype)
var pngname = "image.png"
var contenttype = GetContentType(pngname)
console.log(contenttype)
License
© chasyumen 2021. Released under the MIT license