Windows下详细安装Parse Server后端
准备工作
首先配置环境,需要安装的环境软件nodejs, MongoDB, git
nodejs: https://nodejs.org/zh-cn/ (win7系统装12.x版本的,地址:https://nodejs.org/dist/latest-v12.x/)
MongoDB: https://www.mongodb.com/try/download/community (win7建议装4.0.xx)
git: https://git-scm.com/downloads (下载这个是为了方便安装Parse Dashboard管理面板)
安装完成后百度环境变量配置即可
开始安装
安装Parse Server
npm install -g parse-server
安装Parse管理面板
npm install -g parse-dashboard
以上的安装命令和之前的文章一样,linux系统可以参考:https://pcnto.com/daily-learning/8-centos-system-building-parse-server.html
配置Parse Server和Parse Dashboard
首先如果你的nodejs配置的话,会在nodejs\node_global\node_modules这个目录下,如果没有可以去C盘用户目录下去查找
进入parse-server目录,新建一个index.js(这个名字可以随便命名,能记住即可)
index.js内容放入
const express = require('express');
const { default: ParseServer, ParseGraphQLServer } = require('parse-server');
const app = express();
const parseServer = new ParseServer({
databaseURI: 'mongodb://localhost:27017/parse', //这里放你新建的parse数据库名字
appId: 'myAppId',
masterKey: 'myMasterKey',
serverURL: 'http://localhost:1337/parse',
publicServerURL: 'http://localhost:1337/parse'
});
const parseGraphQLServer = new ParseGraphQLServer(
parseServer,
{
graphQLPath: '/graphql',
playgroundPath: '/playground'
}
);
app.use('/parse', parseServer.app); // (Optional) Mounts the REST API
parseGraphQLServer.applyGraphQL(app); // Mounts the GraphQL API
parseGraphQLServer.applyPlayground(app); // (Optional) Mounts the GraphQL Playground - do NOT use in Production
app.listen(1337, function() {
console.log('REST API running on http://localhost:1337/parse');
console.log('GraphQL API running on http://localhost:1337/graphql');
console.log('GraphQL Playground running on http://localhost:1337/playground');
});
上面代码来自:https://github.com/parse-community/parse-server
这个只会启动 parse server,这样启动的好处是可以使用 GraphQl 和 playground 可视化调试工具
也可以选择用:https://pcnto.com/daily-learning/8-centos-system-building-parse-server.html 里的index.js文件内容
启动Parse Server
node index.js
Parse Dashboard 启动文件
进入parse-dashboard 目录,然后新建一个dashboard.js
var express = require('express');
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
"apps": [
{
"serverURL": "http://localhost:1337/parse",
"appId": "myAppId",
"masterKey": "myMasterKey",
"appName": "MyApp"
}
]
});
var app = express();
// make the Parse Dashboard available at /dashboard
app.use('/dashboard', dashboard);
var httpServer = require('http').createServer(app);
httpServer.listen(4040);
这样可以单独只使用面板,可以控制多个Parse Server,详细信息可以参考官方文档
启动Parse Dashboard
node dashboard.js
然后浏览器输入: http://127.0.0.1:4040/
然后就可以愉快玩耍
搞定,撒花