win7+NodeJS+MongoDB+Smart Table

来源:互联网 发布:八卦九宫打法优化版 编辑:程序博客网 时间:2024/06/16 10:25

一 NodeJS

1.http://nodejs.org/ 下载最新V6.10.0 LTS, 双击安装

2.cmd命令行到安装目录,安装express,运行 D:\nodejs>npm install -g express-generator

   -g 表示全局安装

3.创建express项目,如 express -e nodetest

   -e 表示使用ejs模板 或 --view==ejs

4.安装,到 nodetest 目录 运行 npm install

5.启动 npm start, 查看 http://localhost:3000/


二 MongoDB

1.https://www.mongodb.com下载3.2.8, mongodb-win32-i386-3.2.8-signed (64位处理器请下载64位安装包).

   访问不了网站的,请到其他正规网站下. 我是通过公司网络下的.

2.设置log文件和db目录,在bin目录同级创建data目录,再在data目录创建log和db目录

   mongod --logpath="D:\Program Files\MongoDB\Server\3.2\data\log\log.txt" --dbpath="D:\Program Files\MongoDB\Server\3.2\data\db"

3.Hotfix KB2731284 or later update is not installed问题

   到https://support.microsoft.com/zh-cn/hotfix/kbhotfix?kbnum=2731284&kbln=zh-cn, 填写邮箱

   微软会发一个补丁下载路径的邮件,根据连接地址下载安装补丁,我的是32位的

   http://hotfixv4.microsoft.com/Windows%207/Windows%20Server2008%20R2%20SP1/sp2/Fix405791/7600/free/451412_intl_i386_zip.exe

   64位的 

   http://hotfixv4.microsoft.com/Windows%207/Windows%20Server2008%20R2%20SP1/sp2/Fix405791/7600/free/451413_intl_x64_zip.exe

4. log里提示错误 "The default storage engine 'wiredTiger' is not available"

    加上参数 --storageEngine=mmapv1

5. 查看http://localhost:27017/

    显示  It looks like you are trying to access MongoDB over HTTP on the native driver port.

6. 创建windows服务

    mongod --install --logpath="D:\Program Files\MongoDB\Server\3.2\data\log\log.txt" --dbpath="D:\Program Files\MongoDB\Server\3.2\data\db"  --storageEngine=mmapv1
    services.msc命令查看mongodb服务是否创建成功

    若log里提示"Error connecting to the Service Control Manager",请用管理员身份运行cmd命令行,再执行上面的命令.


三、Angular+Smart Table

1. 下载 AngularJs1.0 到 https://angularjs.org/

     最新版本是1.6.3

2. 下载 Smart Table

     在nodetest目录运行: npm install angular-smart-table

     安装完后可以在  ./node_modules/angular-smart-table/dist 找到相关的 js 文件

     将smart-table.min.js拷贝到目录 ./public/javascripts/smarttable下,目录如果不存在请自行创建

3. 在目录 public/javascripts/ 下创建文件 table.js, 数据可以改成从 MongoDB获取

    var app = angular.module('myApp',['smart-table']);

app.controller('basicsCtrl', ['$scope', function (scope) {
    scope.rowCollection = [
        {firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: 'whatever@gmail.com'},
        {firstName: 'Blandine', lastName: 'Faivre', birthDate: new Date('1987-04-25'), balance: -2323.22, email: 'oufblandou@gmail.com'},
        {firstName: 'Francoise', lastName: 'Frere', birthDate: new Date('1955-08-27'), balance: 42343, email: 'raymondef@gmail.com'}
    ];
}]);


4. 在 views目录下创建文件 table.html

 <!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="UTF-8">  
        <title></title>  
        <link rel='stylesheet' href='/stylesheets/bootstrap.min.css'/>
    </head>  
    <body>     
        <div ng-app="myApp" class="main_table">
        <div ng-controller="basicsCtrl">
        <table st-table="rowCollection" class="table table-striped">
    <thead>
    <tr>
        <th>first name</th>
        <th>last name</th>
        <th>birth date</th>
        <th>balance</th>
        <th>email</th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="row in rowCollection">
        <td>{{row.firstName}}</td>
        <td>{{row.lastName}}</td>
        <td>{{row.birthDate}}</td>
        <td>{{row.balance}}</td>
        <td>{{row.email}}</td>
    </tr>
    </tbody>
</table>
        </div>
        </div>
        <script src="javascripts/angular/1.6.3/angular.min.js"></script>
        <script src='javascripts/smarttable/smart-table.min.js'></script>
        <script src="javascripts/table.js"></script>    
    </body>  
</html> 


Note: 自行下载css文件 bootstrap.min.css

5. 修改 app.js

   加一行

   app.use('/table',index);


6.修改 index.js, 加入下面代码

router.get('/table', function(req, res, next) {
  res.render('table', { title: 'test table' });
});


7.启动服务,访问 http://localhost:3000/table



四、参考网址
1. http://lorenzofox3.github.io/smart-table-website/



0 0
原创粉丝点击