Parse Server和Parse DashBoard是parse系列两个最重要的模块,本章讲述如何简单快速的在本地配置。
后面还会推出更多相关教程。
不废话,直接上代码!
一、新建package.json
{
"name":"parse-server-dashboard",
"version":"1.0.0",
"description":"An example run parse-server and parse-dashboard together",
"main":"index.js",
"license":"MIT",
"dependencies": {
"express":"~4.11.x",
"parse":"~1.8.0",
"parse-dashboard":"*",
"parse-server":"*",
"pug":"^2.0.0-rc.4"
},
"scripts": {
"start":" supervisor index.js"
},
"engines": {
"node":">=4.3"
}
}
npm install 安装依赖文件。
二、新建配置文件,创建config文件夹,index.js
module.exports={
serverPort:4040,
serverURL:"http://localhost:4040/parse",
databaseURI:"mongodb://localhost/blog"
};
三、新建index.js
varexpress = require('express');
$config=require('./config');
varParseServer =require('./server/Parse_Server');
varParseDashboard = require('./server/Parse_Dashboard');
varapp = express();
// 把 Parse Server 挂载在 /parse
app.use('/parse', ParseServer);
// 把 Parse Dashboard 挂载在 /dashboard
app.use('/dashboard', ParseDashboard);
varhttpServer = require('http').createServer(app);
httpServer.listen($config.serverPort,function(){
console.log('parse-server parse-dashboard are running on port 4040.');
});
四、新建server文件夹,并创建
Parse_Server.js
varParseServer=require('parse-server').ParseServer;
varapi=newParseServer({
"appId":"asdhwu648vx",
"masterKey":"lkasni654zdw",
"appName":"blog",
"databaseURI":$config.databaseURI,
"serverURL":$config.serverURL
});
module.exports=api;
以及
Parse_Dashboard.js
varParseDashboard=require('parse-dashboard');
vardashboard=newParseDashboard({
"apps": [{
"serverURL":$config.serverURL,
"appId":"asdhwu648vx",
"masterKey":"lkasni654zdw",
"appName":"Myblog"}]
});
module.exports=dashboard;
最后再npm start
控制台成功输出:
parse-server parse-dashboard are running on port 4040.
浏览器打开
http://localhost:4040/dashboard
显示以下图片:
收工!
源代码:https://github.com/vtista/parse-server-dashboard