安装 FMS

Node

原文地址:http://fms.help/beginning.html

请确保你安装了 Node
打开 http://nodejs.org/ 点击 Download 或 Install

如果你不了解 Node 请务必阅读 Node 安装启动测试

FMS

成功安装 Node 后在命令行 输入

npm install fms
# 或者安装到全局
npm install fms -g

nodemon

建议使用 nodemon 启动 FMS,nodemon 可以监控代码修改后重启 node 服务

npm install nodemon -g

Mac 用户请输入 sudo npm install nodemon -g

启动

创建 fms.js 文件,文件内容如下:

var fms = require('fms')
fms.run()
fms.ajax({
    url: '/test/',
    type: 'get',
    res: {
        ok: 'yes',
        err: 'no'
    }
})

创建 index.html文件,文件内容如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FMS Demo</title>
</head>
<body>
<script src="http://apps.bdimg.com/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
$.ajax({
    url: '/test/',
    type: 'get'
}).done(function (data) {
    $('body').html(data)
})
</script>
</body>
</html>

使用命令行切换到 fms.js 所在目录

cd C:目录路径
例如:cd C:
imojsfms

使用 node 或 nodemon 运行 fms.js

node fms.js
nodemon -w fms.js fms.js

nodemon 将会监听 fms.js 文件的修改,当文件被编辑后将会重新启动 fms.js

启动成功后将会提示

[F.M.S] Running at http://127.0.0.1:3000

若想关闭请按 Ctrl + C

如果提示 Error: Cannot find module 'fms'
则表示你没有在当前目录安装 FMS,请在命令行运行 npm install fms

打开 http://127.0.0.1:3000 可以看到FMS的控制界面和文档
打开 http://127.0.0.1:3000/index.html http://127.0.0.1:3000/test/ 或 可以查看模拟 AJAX 效果

快速入门

上一篇:安装与启动

下一篇:配置

下载

下载 fms-demo 项目学习使用 FMS 下载快速入门示例 示例源码

下载解压后务必切换到 fms-demo 根目录安装 FMS

Widnows 用户建议解压到 C 盘

npm install fms

nodemon

建议使用 nodemon 启动 FMS,nodemon 可以监控代码修改后重启 node 服务

npm install nodemon -g

Mac 用户请输入 sudo npm install nodemon -g

启动

# 一定要在 fms-demo 根目录运行
# 监控 fms.js 文件修改后重启 fms.js
nodemon -w fms.js fms.js
# 成功出现提示
21 Oct 23:17:45 - [nodemon] 1.7.2
21 Oct 23:17:45 - [nodemon] to restart at any time, enter `rs`
21 Oct 23:17:45 - [nodemon] watching: fms.js
21 Oct 23:17:45 - [nodemon] starting `node fms.js`
[F.M.S] Running at http://127.0.0.1:3000

请打开 http://127.0.0.1:3000 查看效果

control get_user

代码解释

fms.ajax({
    type: 'get',
    title: '获取用户名',
    request: {
        id: '2',
        _id: "用户ID"
    },
    url: '/get_user/',
    res: {
        ok: {
            status: "success",
            username: "fms"
        },
        err: {
            status: "error",
            msg: "请先登录"
        }
    }
})

/get_user/ 接受 GET 方式的 AJAX 请求,此 AJAX 的作用是获取用户名。返回的数据会有2种情况:

// 成功
{
    "status": "success",
    "username": "fms"
}
// 失败
{
    "status": "error",
    "msg": "请先登录"
}

此 AJAX 将会接受 id 参数,此参数的内容是用户ID

可以在 http://127.0.0.1:3000/ 页面中通过 选择 select 控制 http://127.0.0.1:3000/get_user/ 的返回结果

原文地址:https://www.cnblogs.com/zoumiaomiao/p/4917483.html