Skip to content

Commit f67b776

Browse files
committed
🏗️ Load cloud functions from functions folder
1 parent 84ed757 commit f67b776

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Node.js Getting started
22
在 LeanCloud 云引擎上使用 Express 的 Node.js 示例项目。
33

4+
若希望获取更多常见功能和代码片段,请访问 [leancloud/leanengine-nodejs-demos](https://github.com/leancloud/leanengine-nodejs-demos)
5+
46
## 本地运行
57

68
首先确认本机已经安装 [Node.js](http://nodejs.org/) 运行环境和 [LeanCloud 命令行工具](https://leancloud.cn/docs/leanengine_cli.html),然后执行下列指令:
79

810
```
9-
$ git clone https://github.com/leancloud/node-js-getting-started.git
10-
$ cd node-js-getting-started
11+
git clone https://github.com/leancloud/node-js-getting-started.git
12+
cd node-js-getting-started
1113
```
1214

1315
安装依赖:

cloud.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
var AV = require('leanengine');
1+
const AV = require('leanengine')
2+
const fs = require('fs')
3+
const path = require('path')
4+
5+
/**
6+
* 加载 functions 目录下所有的云函数
7+
*/
8+
fs.readdirSync(path.join(__dirname, 'functions')).forEach( file => {
9+
require(path.join(__dirname, 'functions', file))
10+
})
211

312
/**
413
* 一个简单的云代码方法
514
*/
615
AV.Cloud.define('hello', function(request) {
7-
return 'Hello world!';
8-
});
16+
return 'Hello world!'
17+
})

functions/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)