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

nacos-nestjs-util

v1.0.9

Published

1.服务注册逻辑: (1)注册服务时,如果服务器设置了环境变量HOST_IP和SERVER_PORT,那么会把HOST_IP和SERVER_PORT作为服务的IP和PORT进行注册。 (2)如果服务器没有设置环境变量,那么获取.env相关配置(SERVICE_IP,PORT)作为服务的IP和PORT进行注册。 (3)如果本地未配置,那么自动获取服务器IP以及使用默认端口3000进行服务注册。 2.新增获取服务实例集合方法 ## 介绍 本工具基于NestJs8.0以及nacos2.2.1,用于微

Downloads

4

Readme

1.0.8更新内容

1.服务注册逻辑: (1)注册服务时,如果服务器设置了环境变量HOST_IP和SERVER_PORT,那么会把HOST_IP和SERVER_PORT作为服务的IP和PORT进行注册。 (2)如果服务器没有设置环境变量,那么获取.env相关配置(SERVICE_IP,PORT)作为服务的IP和PORT进行注册。 (3)如果本地未配置,那么自动获取服务器IP以及使用默认端口3000进行服务注册。 2.新增获取服务实例集合方法

介绍

本工具基于NestJs8.0以及nacos2.2.1,用于微服务中服务发现注册,注销,以及访问服务等。

要求

  1. 需要开启nest框架中的shutdownHooks,再应用的生命周期中做注册以及注销。
  2. 设置globalPrefix需要和注册的服务名称一致(被调用的服务一样,context-path也需要与服务名一致)
  3. 注册服务的端口号和应用的端口号一致

使用

  1. 安装
>npm install nacos-nestjs-util --save
>npm install nacos --save
  1. 在.env文件中增加如下配置,注意:NestJs获取.env文件需要添加ConfigModule,具体参考官方文档
    imports:[ConfigModule.forRoot({
      envFilePath: ['.env', '.env.' + process.env.NODE_ENV],
    })],
DISCOVERY_SERVERLIST = 192.168.56.101:1234 #配置nacos服务地址
DISCOVERY_NAMESPACE = public #配置nacos的空间名称(服务也是注册到此空间)
DISCOVERY_GROUP = UAT #配置nacos的分组名称
DISCOVERY_APPNAME = node-service #本服务名称
SERVICE_IP = 192.168.1.111 #本服务IP(可选)
PORT = 3000 #本服务端口号(可选)
HTTP_PREFIX = http:// #访问URI的前缀
  1. 开启shutdownHooks
  app.enableShutdownHooks();
  1. 配置全局前缀以及端口号
  app.setGlobalPrefix(process.env.DISCOVERY_APPNAME); //请求前缀
  await app.listen(process.env.PORT);
  1. 在根module导入HookModule
imports:[HookModule]
  1. 调用服务示例
        //获取服务temp-service的uri
        const uri = await NacosUtil.getServiceUriWithL('temp-service');
        //如果配置了分组请传入所属分组
        #const uri = await NacosUtil.getServiceUriWithL('temp-service', 'groupName');
        //调用temp-service提供的/demo/user/list接口
        const result = await axios.post(uri + '/demo/user/list', {});

API列表

    /**
     * 根据服务名返回健康并启用的实例URI
     * @param serviceName 需要调用的服务名
     * @param groupName 分组名称,如果传空默认DEFAULT_GROUP 
     * @return uri
     */
    static async getServiceUri(serviceName: string, groupName: string);

    /**
     * 随机返回一个健康并启用的实例URI
     * @param serviceName 需要调用的服务名
     * @param groupName 分组名称,如果传空默认DEFAULT_GROUP
     * @return uri
     */
    static async getServiceUriWithLB(serviceName: string, groupName: string);

    /**
     * 根据服务名和组名获取服务实例集合
     * @param serviceName 需要调用的服务名
     * @param groupName 分组名称,如果传空默认DEFAULT_GROUP
     * @return instanceList 
     */
    static async getInstanceListBySerName(serviceName: string, groupName: string);