
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@ouyangdan/nodejs-api-demo
Advanced tools
基于 eggjs + dubbo2.js 搭建的nodejs-java后端rpc微服务框架。
详细参考egg官方文档 egg docs
$ npm i
$ npm run dev
$ open http://localhost:7002/
$ npm start
$ npm stop
npm run lint to check code style.npm test to run unit test.npm run autod to auto detect dependencies upgrade, see autod for more detail.nodejs 使用原生的 dubbo 协议打通了 dubbo 的 rpc 方法调用 .
yarn add dubbo2.js
import {Dubbo, java, TDubboCallResult} from 'dubbo';
//定义dubbo方法类型接口
//方便代码自动提示
//如果写的JavaScript忽略
interface IDemoService {
sayHello(name: string): TDubboCallResult<string>;
echo(): TDubboCallResult<string>;
test(): TDubboCallResult<void>;
getUserInfo(): TDubboCallResult<{
status: string;
info: {id: number; name: string};
}>;
}
//创建dubbo对象
const dubbo = new Dubbo({
application: {name: 'node-dubbo'},
//zookeeper address
register: 'localhost:2181',
dubboVersion: '2.0.0',
interfaces: ['com.alibaba.dubbo.demo.DemoService'],
});
//代理本地对象->dubbo对象
const demoService = dubbo.proxyService<IDemoService>({
dubboInterface: 'com.alibaba.dubbo.demo.DemoService',
version: '1.0.0',
methods: {
sayHello(name) {
//仅仅做参数hessian化转换
return [java.String(name)];
},
echo() {},
test() {},
getUserInfo() {
//仅仅做参数hessian化转换
return [
java.combine('com.alibaba.dubbo.demo.UserRequest', {
id: 1,
name: 'nodejs',
email: 'node@qianmi.com',
}),
];
},
},
});
const result1 = await demoService.sayHello('node');
//print {err: null, res:'hello node from dubbo service'}
const res = await demoService.echo();
//print {err: null, res: 'pang'}
const res = await demoService.getUserInfo();
//status: 'ok', info: { id: '1', name: 'test' }
创建 Dubbo 对象
const dubbo = new Dubbo({
dubboVersion //当前dubbo的版本 (string类型); 必传
application //记录应用的名称,zookeeper的调用时候写入consumer 类型:({name: string};) 可选
enableHeartBeat //是否启用心跳机制 默认true 可选 类型 boolean
dubboInvokeTimeout //设置dubbo调用超时时间默认10s 可选 类型number
dubboSocketPool //设置dubbo创建socket的pool大小,默认4 可选 类型number
logger //设置logger对象,可选
register //设置zookeeper注册中心地址 必填 类型string
zkRoot //zk的默认根路径,默认/dubbo 类型string
interfaces //设置zk监听的接口名称 类型 Array<string> 必填
});
// Or
const dubbo = Dubbo.from({
dubboVersion //当前dubbo的版本 (string类型); 必传
application //记录应用的名称,zookeeper的调用时候写入consumer 类型:({name: string};) 可选
enableHeartBeat //是否启用心跳机制 默认true 可选 类型 boolean
dubboInvokeTimeout //设置dubbo调用超时时间默认10s 可选 类型number
dubboSocketPool //设置dubbo创建socket的pool大小,默认4 可选 类型number
logger //设置logger对象,可选
register //设置zookeeper注册中心地址 必填 类型string
zkRoot //zk的默认根路径,默认/dubbo 类型string
interfaces //设置zk监听的接口名称 类型 Array<string> 必填
})
//dubbo的代理服务
const demoSerivce = Dubbo.proxService({
//代理的服务接口 - string 必传
dubboInterface: 'com.alibaba.dubbo.demo.DemoService',
//服务接口的版本 - string 必传
version: '1.0.0',
//接口内的方法 - Array<Function> 必传
methods: {
//method name
xx(params) {
return [
params
]
}
},
})
import {Dubbo} from 'dubbo2.js';
默认导入的 dubbo2.js 是按照 es2017 进行编译的,支持 node7.10 以上。
如果更低的 node 版本,可以使用
import {Dubbo} from 'dubbo2.js/es6';
http://localhost:7002/swagger-ui.html
具体实现参考:https://juejin.cn/post/6974952982076981284#heading-5
支持多数据库连接
注:项目默认的Mysql数据库使用链股开发环境的数据库,实际开发需要在config/config.{dev}.js配置文件中改成你自己项目的数据库地址及账号密码。
支持ORM框架Sequelize
注:项目默认的Mysql数据库使用链股开发环境的数据库,实际开发需要在config/config.{dev}.js配置文件中改成你自己项目的数据库地址及账号密码。
支持redis增删改查。
注:项目默认的redis服务器地址及账号密码使用链股开发环境的redis,实际开发需要在config/config.{dev}.js配置文件中改成你自己项目的redis服务器地址及账号密码。
FAQs
nodejs后端基础框架
We found that @ouyangdan/nodejs-api-demo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.