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

nodeway

v2.0.5

Published

nodeway microservices

Downloads

10

Readme

nodeway: 基于nodejs的微服务(Microservices)

一个微服务(Microservices)被定义为一个JS类(Class)。
nodeway直接发布这个JS类,使浏览器或nodejs可以远程调用。

Installing

# npm install nodeway -g

MacOS

# vi ~/.bash_profile
export NODE_PATH="/usr/local/lib/node_modules:/root/node_modules"

Linux

# vi ~/.bashrc
export NODE_PATH="/usr/local/lib/node_modules:/root/node_modules"

Using

# nodeway

  Usage: nodeway [options]

  Options:

    -h, --help                  output usage information
    -V, --version               output the version number
    --class <class>[,<class>]*  class list
    --host <host>               Listen ip or hostname, default '127.0.0.1'
    --port <port>               Listen port, default '80'
    --docs [root]               Httpd docs root, optional
    --config <file>             Config file

  Prompt:

    Either --class or --config must be one.

Example 'HelloWorld.js'

建立测试目录,在测试目录下创建'HelloWorld.js'微服务,内容如下:

const Nodeway = require("nodeway");

class HelloWorld extends Nodeway {
    constructor(uuid) {
        super(uuid);
    }
    async say(message) {
        this.broadcast('data', `${message}(${Nodeway.onlineCount})`);
        return new Promise(function(resolve, reject) {
            resolve(message);
        });
    }
}

module.exports = HelloWorld;

Run

# nodeway --config nodeway-helloworld/config.js &

Test

编写浏览器调用微服务测试文件'index.html',内容如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>HelloWorld</title>
    <script type="text/javascript" src="/HelloWorld.js"></script>
</head>
<body>
<script>
let api = new HelloWorld;
api.on('data', message => document.write(message+'<br/>'));
setInterval(async function(api) {
    try {
        let message = await api.say('Hello Safari!');
        document.write(message+'<br/>');
    }
    catch(e) {}
}, 6000, api);
</script>
</body>
</html>

在浏览器中访问'http://localhost:8080'进行测试。

编写nodejs调用微服务测试文件'test_from_nodejs.js',内容如下:

const requireFromUrl = require('require-from-url');
const readline = require('readline');

function main(HelloWorld) {
    let api = new HelloWorld;
    api.on('data', console.log);

    readline.createInterface({
        input: process.stdin,
        output: process.stdout
    })
    .on('line', async function(line) {
        try {
            let message = await api.say(line.trim());
            console.log(message);
        }
        catch(e) {}
    })
    .on('close', process.exit);
}

requireFromUrl(["http://localhost:8080/HelloWorld.js"], function(err, HelloWorld) {
    if(!err) main(HelloWorld);
});

执行node test_from_nodejs.js进行测试。

你也可以用命令npm install nodeway_helloworld直接安装这个测试例子。

License

MIT © May xiaoya zhang