npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lite-dev-server

v3.2.7

Published

This is http file server for develpment. This server supports livereload function and proxy function for your api server.

Downloads

109

Readme

lite-dev-server

This is http file server for develpment. This server supports livereload function and proxy function for your api server.

Latest Stable Version License


Video tutorial

Perhaps you may be interested: webpack-with-lite-dev-server-babel-koa-react

Installation

$ npm install lite-dev-server --save-dev

or

$ yarn add lite-dev-server -D

Usage (default port: 3000)

const liteDevServer = require("lite-dev-server");
liteDevServer( { folder: "public", watchFolders: ["public"]} );
// http://localhost:3000 response: index.html or index.htm from public folder.

Attention: If the html document does not contain a head tag, then liveReload will not work.

Usage (on 3333 port)

const liteDevServer = require("lite-dev-server");
liteDevServer( { folder: "public", watchFolders: ["public"], listen: 3333,} ); 
// http://localhost:3333 response: index.html or index.htm from public folder.

Usage (random port)

const liteDevServer = require("lite-dev-server");
const server = liteDevServer( { folder: "public", watchFolders: ["public"], listen: 0,} ); 
console.log(server.address().port) // your port

Close server

const liteDevServer = require("lite-dev-server");
const server = liteDevServer( { folder: "public", watchFolders: ["public"]} );

server.close(); // Close http server
server.wss.close(); // Close websocket server
server.watchers[0].close(); // Close watcher
server.closeAllWatchers(); // Close all watchers

Usage with proxy function for Express api server

const liteDevServer = require("lite-dev-server");
liteDevServer({
    folder: "public",
    watchFolders: ["public", "src"],
    proxy: [
        { path: /\/api/, host: "localhost", port: "8888" },
        { path: /\/api2/, host: "localhost", port: "8888" }
    ]
});
// http://localhost:3000 response: index.html or index.htm from public folder.
// http://localhost:3000/api/1 response: "Hello World!!" from express
// http://localhost:3000/api2/person/1 response: "person1" from express

const express = require('express');
const app = express();

app.get('/api/1', function (req, res) {
    res.send('Hello World!!')
});

app.get('/api2/person/1', function (req, res) {
    res.send('person1')
});
app.listen(8888);

Api

create liteDevServer

const liteDevServer = require("lite-dev-server");
liteDevServer({
    folder: "public",
    watchFolders: ["public", "src"],
    listen: 3000,
    webSocketPort: 8080,
    page404: null,
    liveReload: true,
    reloadDelay: 200,
    autoInjectClientJS: true,
    historyApiFallback: false,
    reloadDelayOnClient: 1000,
    giveDefaultPage: true,
    defaultPageFirst: "index.html",
    defaultPageSecond: "index.htm",
    serverName: "liteDevServer",
    pathRewrite: {
      pattern: /\/.+\/(\.*)/g,
      replacement: "/$1",
    },
    proxy: [
        { path: /\/api/, host: "localhost", port: "8888" },
        { path: /\/api2/, host: "localhost", port: "8888" },
        { path: /\/gavrilov\/project/, host: "localhost", port: "3000", pathRewrite: {
            pattern: /\/gavrilov\/project/,
            replacement: "",
        }}
    ]
});

Arguments:

  • options (Object type):*

    • folder (String) (default value: "public"): Folder for static files.

    • watchFolders (Array of Strings) (default value: ["public"]): Folders for watching (for liveReload).

    • proxy (Array of Objects) (default value: []): Proxy for API (Express, Koa, etc.).

    • listen (Integer) (default value: 3000): Port for development server (serve static files).

    • webSocketPort (Integer) (default value: 8080): For liveReload.

    • page404 (String | Null) (default value: null): Custom page.

    • liveReload (Boolean) (default value: true).

    • reloadDelayOnClient (Integer) (default value: 100): reload delay for liveReload (on client) (in milliseconds).

    • liveReloadDelay (Integer) (default value: 0): Delay before the page is reloaded (on server) (in milliseconds).

    • autoInjectClientJS (Boolean) (default value: true): Auto inject javascript in html documents (for liveReload).

    • historyApiFallback (Boolean) (default value: false): If you are using the HTML5 history API you probably need to serve your index.html in place of 404 responses, which can be done by setting historyApiFallback: true.

    • giveDefaultPage (Boolean) (default value: true)

    • defaultPageFirst (String) (default value: "index.html")

    • defaultPageSecond (String) (default value: "index.htm")

    • serverName (String) (default value: "liteDevServer")

    • pathRewrite (Object | Array of Objects | Null) (default value: null)

License

MIT License

Copyright (c) 2017 Gavrilov Ruslan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.