{"id":19614836,"url":"https://github.com/leancloud/leanengine-nodejs-demos","last_synced_at":"2025-04-28T02:30:46.440Z","repository":{"id":32478592,"uuid":"36058825","full_name":"leancloud/leanengine-nodejs-demos","owner":"leancloud","description":"云引擎 Node.js 常用功能和示例汇总","archived":false,"fork":false,"pushed_at":"2023-05-18T07:33:50.000Z","size":212,"stargazers_count":109,"open_issues_count":3,"forks_count":49,"subscribers_count":34,"default_branch":"master","last_synced_at":"2024-04-13T06:30:15.299Z","etag":null,"topics":["leancloud","leanengine"],"latest_commit_sha":null,"homepage":"https://leancloud.cn/docs/leanengine_webhosting_guide-node.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leancloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-22T07:37:50.000Z","updated_at":"2024-04-06T14:42:07.000Z","dependencies_parsed_at":"2022-08-27T06:50:46.218Z","dependency_job_id":null,"html_url":"https://github.com/leancloud/leanengine-nodejs-demos","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fleanengine-nodejs-demos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fleanengine-nodejs-demos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fleanengine-nodejs-demos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2Fleanengine-nodejs-demos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leancloud","download_url":"https://codeload.github.com/leancloud/leanengine-nodejs-demos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224092043,"owners_count":17254152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["leancloud","leanengine"],"created_at":"2024-11-11T10:54:08.937Z","updated_at":"2024-11-11T10:54:10.133Z","avatar_url":"https://github.com/leancloud.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LeanEngine Node.js Demos\n\n该项目是 [LeanEngine](https://leancloud.cn/docs/leanengine_overview.html) Node.js 项目的常用功能和示例仓库。包括了推荐的最佳实践和常用的代码片段，每个文件中都有较为详细的注释，适合云引擎的开发者阅读、参考，也可以将代码片段复制到你的项目中使用。\n\n若希望从一个更精简的项目骨架开始开发你的新项目，请使用 [leancloud/node-js-getting-started](https://github.com/leancloud/node-js-getting-started)。\n\n## 功能列表（云函数）\n\n下面列出的功能均以云函数实现，位于 `functions` 目录中。每个文件的开头已列出所需的依赖和配置（环境变量），你可以在安装依赖后将文件直接复制到你的 `functions` 目录中，我们的示例项目会自动加载这个目录中的文件。\n\n对于需要 LeanCache 的功能，还请阅读下面的 [LeanCache](#LeanCache) 段落。\n\n✅表示写了测试，✨表示实现了相对完整的功能，无需修改即可使用。\n\n| 文件名       | 提供的云函数 | 介绍 |\n| ------------ | ------------ | ---- |\n| [amr-transcoding.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/amr-transcoding.js) | amrToMp3 | 使用 ffmpeg 将 amr 音频转码为 mp3。 |\n| [associated-data.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/associated-data.js) | createPostSamples\u003cbr\u003egetPostsWithAuthor\u003cbr\u003egetPostWithAuthor\u003cbr\u003eafterUpdate:_User | 缓存关联数据示例（需要 LeanCache）。 |\n| [batch-update.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/batch-update.js) | batchUpdateByQuery\u003cbr\u003ebatchUpdateAll | 批量更新数据示例。 |\n| [captcha-cache.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/captcha-cache.js) | getCaptchaImageCache\u003cbr\u003erequestMobilePhoneVerifyCache | 使用图形验证码限制短信接口（使用 LeanCache）（需要 LeanCache）。  |\n| [captcha-storage.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/captcha-storage.js) | getCaptchaImageStorage\u003cbr\u003erequestMobilePhoneVerifyStorage | ✅ 使用图形验证码限制短信接口（使用云存储后端）。  |\n| [crawler.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/crawler.js) | crawlWebsite\u003cbr\u003ecrawling | 爬虫示例，使用云队列抓取一个站点下的所有网页。 |\n| [imagemagick.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/imagemagick.js) | imageMagicResize | ✅ 使用 imageMagick 处理图像。 |\n| [leaderboard.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/leaderboard.js) | submitHighest\u003cbr\u003egetRankRange\u003cbr\u003egetScoreRange\u003cbr\u003egetRankAndScore\u003cbr\u003earchiveLeaderboard | ✨ 一个功能相对完整的排行榜，支持任意数量的用户排序、支持查询任意用户的排名、支持查询任意排名段的用户（需要 LeanCache）。  |\n| [limited-stock-rush.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/limited-stock-rush.js) | createRushStock\u003cbr\u003egetOpeningRushs\u003cbr\u003erush\u003cbr\u003ecommitRushStock | ✨ 使用 LeanCache 应对秒杀抢购活动中短时间的大量请求（需要 LeanCache）。  |\n| [login-by-app.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/login-by-app.js) | requestLoginByApp\u003cbr\u003everifyByApp\u003cbr\u003eloginByApp | 通过移动端应用验证用户身份，登录网站（比如扫码登录）。|\n| [meta.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/meta.js) | getEnvironments\u003cbr\u003egetUser\u003cbr\u003egetParams\u003cbr\u003egetClientMeta\u003cbr\u003egetHeaders\u003cbr\u003eafterSave:HookObject | 从运行环境或客户端读取元信息（环境变量、请求头等）。 |\n| [pubsub.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/pubsub.js) | publishMessage | 使用 Redis Pub/Sub 收发消息。 |\n| [queue-delay-retry.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/queue-delay-retry.js) | queueDelayTask\u003cbr\u003equeueRetryTask\u003cbr\u003edelayTaskFunc\u003cbr\u003eretryTaskFunc | 云队列：延时和重试。云函数任务队列提供了一种可靠地对云函数进行延时运行、重试、结果查询的能力。 |\n| [queue-result-query.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/queue-result-query.js) | createTask\u003cbr\u003equeryResult\u003cbr\u003elongRunningTask | 云队列：结果查询 |\n| [readonly.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/readonly.js) | updateCategory\u003cbr\u003egetCategories\u003cbr\u003eafterUpdate:Category\u003cbr\u003eafterSave:Category\u003cbr\u003eafterDelete:Category\u003cbr\u003erefreshCategories | 热点只读数据缓存示例（需要 LeanCache）。 |\n| [redlock.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/redlock.js) | startTaskLoop\u003cbr\u003egetCurrentTask | 用 LeanCache 实现分布式锁（需要 LeanCache）。 |\n| [rtm-signature.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/rtm-signature.js) | signLogin\u003cbr\u003esignStartConversation\u003cbr\u003esignOperateConversation\u003cbr\u003esignQueryMessage\u003cbr\u003esignBlockConversation\u003cbr\u003esignBlockClient | ✅ 使用云引擎实现即时通讯服务的签名。 |\n| [todos.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/todos.js) | getAllTodos\u003cbr\u003ecreateTodo\u003cbr\u003edeleteTodo\u003cbr\u003esetTodoToDone | 在云引擎中以客户端的权限来操作云存储。 |\n| [weapp-decrypt.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/weapp-decrypt.js) | decryptWeappData | ✨ ✅ 解密微信小程序用户加密数据。 |\n| [xml.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/xml.js) | xmlBuildObject | 使用云函数序列化 XML 对象。 |\n| [rtm-onoff-status.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/functions/rtm-onoff-status.js) | _clientOnline\u003cbr\u003e_clientOffline\u003cbr\u003egetOnOffStatus | 即时通讯上下线状态的存储以及查询（需要 LeanCache）。 |\n\n## 功能列表（网站托管）\n\n下面列出的功能位于 `routes` 目录。每个文件的开头已列出所需的依赖和配置（环境变量），有些功能需要额外的配置，请阅读文件开头的说明，你可以在安装依赖后将文件直接复制到你的 `routes` 目录中，然后在 `app.js` 中引用，例如：\n\n```javascript\napp.use('/wechat', require('./routes/wechat-message-callback'))\n```\n\n| 文件名        | 介绍 |\n| ------------  | ---- |\n| [wechat-message-callback.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/routes/wechat-message-callback.js) | 接收并自动回复 [微信公众平台的用户消息回调](https://mp.weixin.qq.com/wiki?t=resource/res_main\u0026id=mp1421140543)  |\n| [websocket.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/routes/websocket.js) | 简单的 WebSocket 示例：将客户端发来的消息原样发回客户端（echo）、每隔一秒向客户端发送一条消息（timer） |\n| [cookie-session.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/routes/cookie-session.js) | 使用 Cookie Session 在 Cookie 中维持用户登录状态 |\n| [render-ejs.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/routes/render-ejs.js) | 使用 EJS 渲染 HTML 页面 |\n| [markdown.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/routes/markdown.js) | 项目主页，将 README.md 渲染成 HTML 显示在页面上 |\n\n## 其他 Demo\n\n还有一些功能相对完备的 Demo 被制作成了独立的应用：\n\n| Demo 地址        | 代码地址 | 介绍 |\n| ------------  | ---- | ---- |\n| [snapcat.leanapp.cn](https://snapcat.leanapp.cn/?url=https://leancloud.cn/docs) | [snapcat 分支](https://github.com/leancloud/leanengine-nodejs-demos/tree/snapcat) | 一个使用 chrome-headless 的截图服务。 |\n| [graphql.leanapp.cn](https://graphql.leanapp.cn) | [leancloud/leancloud-graphql](https://github.com/leancloud/leancloud-graphql) | 运行在云引擎上的第三方 GraphQL 支持，允许你用 GraphQL 查询 LeanCloud 云存储中的所有数据。 |\n| [leanticket.cn](https://leanticket.cn) | [leancloud/ticket](https://github.com/leancloud/ticket) | 运行在云引擎上的工单系统（即 LeanCloud 官方客服系统） |\n| [status.leancloud.cn](https://status.leancloud.cn) | [leancloud/leancloud-status](https://github.com/leancloud/leancloud-status) | LeanCloud 服务状态页。 |\n\n## 脚本\n\n这些工具脚本位于 `bin` 目录：\n\n| 文件名        | 使用方法 | 介绍 |\n| ------------  | ---- | ---- |\n| [load-test](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/bin/load-test.js) | `load-test 30` | 对自定义的代码片段进行压力测试的工具，会给出速率和耗时等统计数据。 |\n\n## LeanCache\n\n对于用到了 LeanCache 的功能，你需要在控制台上创建 LeanCache 实例，复制该项目根目录的 [redis.js](https://github.com/leancloud/leanengine-nodejs-demos/blob/master/redis.js) 到你的项目，并修改其中的 LeanCache 名称。\n\n本地运行 Redis:\n\n* Mac 运行 `brew install redis` 安装，然后用 `redis-server` 启动。\n* Debian/Ubuntu 运行 `apt-get install redis-server`, CentOS/RHEL 运行 `yum install redis`.\n* Windows 尚无官方支持。\n\n## 相关文档\n\n* [云引擎总览](https://leancloud.cn/docs/leanengine_overview.html)\n* [云函数开发指南](https://leancloud.cn/docs/leanengine_cloudfunction_guide-node.html)\n* [网站托管开发指南](https://leancloud.cn/docs/leanengine_webhosting_guide-node.html)\n* [JavaScript 开发指南](https://leancloud.cn/docs/leanstorage_guide-js.html)\n* [JavaScript SDK API](https://leancloud.github.io/javascript-sdk/docs/)\n* [Node.js SDK API](https://github.com/leancloud/leanengine-node-sdk/blob/master/API.md)\n* [命令行工具使用指南](https://leancloud.cn/docs/leanengine_cli.html)\n* [LeanCache 使用指南](https://leancloud.cn/docs/leancache_guide.html)\n* [云引擎常见问题和解答](https://leancloud.cn/docs/leanengine_faq.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fleanengine-nodejs-demos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleancloud%2Fleanengine-nodejs-demos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fleanengine-nodejs-demos/lists"}