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

mockstar-local-server

v1.3.21

Published

Local server for MockStar

Downloads

18

Readme

mockstar-local-server

MockStar 的本地 server 服务。

1. 安装

$ npm install mockstar-local-server --save

2. API

2.1 startServer(configOpts, callback)

启动本地服务

  • configOptsObject, 请求参数
    • configOpts.rootPathString, 项目根目录
    • configOpts.buildPathString, 构建之后的目录
    • configOpts.logPathString, 日志目录
    • configOpts.mockServerPathString, mock server 根目录
    • configOpts.portNumber, 本地服务的端口号
    • configOpts.nameString, 应用的名字
    • configOpts.isDevBoolean, 是否为开发模式
    • configOpts.watchBoolean, 是否支持watch
  • callbackFunction, 回调函数,接受两个参数 isSuccesslocalServerConfig

该方法会返回一个 http server 对象,可以调用 runServer.stop() 方法来停止服务。

const path = require('path');
const mockstarLocalServer = require('mockstar-local-server');

// 服务启动参数
const configOpts = {
    rootPath: __dirname,
    mockServerPath: path.resolve(__dirname, '../../../mockstar/test/data/fixtures/mock_server/mockers')
};

// 启动本地服务
const runServer = mockstarLocalServer.startServer(configOpts, (isSuccess, data) => {
    console.log('startServer callback', isSuccess, data);
});

// 3s 之后停止服务
setTimeout(() => {
    runServer.stop(() => {
        console.log('stop server success!');
    });
}, 3000);

2.2 findAvailablePort(port)

从指定的 port 端口号开始,找到当前未被占用的端口号,返回一个 Promise

const mockstarLocalServer = require('mockstar-local-server');

mockstarLocalServer.findAvailablePort(9528)
    .then((port) => {
        console.log('Found it port=' + port);
    })
    .catch((err) => {
        console.error(err);
    });

2.3 getLocalServerConfig(configOpts, opts)

获取最终的配置数据。

2.4 getMockServerPath(rootPath, mockServerPath)

获得 mock server 的根目录绝对路径。

  • rootPathString, 项目根目录
  • mockServerPathString,mock server 目录

2.5 getBuildPath(rootPath, buildPath)

获得 mock server 的构建之后的根目录绝对路径。

  • rootPathString, 项目根目录
  • buildPathString, 构建目录

2.6 getLogPath(rootPath, buildPath, logPath)

获得 mock server 的日志绝对路径。

  • rootPathString, 项目根目录
  • buildPathString,构建目录
  • logPathString, 日志目录