在使用Vagrant启动的CentOS上搭建并启动mean环境
由於按照mean.io上的步驟並不順利,我為了自己的方便寫下了一些筆記。
请参考以上内容。
-
- http://mean.io/
- https://github.com/linnovate/mean/wiki/Getting-Started
环境信息
対象バージョンCentOS6.6NodeJS0.10.33NPM1.4.28MongoDB2.6.5mean-cli0.4.0
预先工作
在Vagrant上启动CentOS6
$ sudo yum update -y
安装 Git
$ sudo yum install -y git
安装MongoDB
$ sudo vi /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
$ sudo yum install -y mongodb-org
$ sudo /etc/init.d/mongod start
安装NodeJS
$ curl -sL https://rpm.nodesource.com/setup | sudo bash -
$ sudo yum install -y nodejs
创建和执行环境
$ sudo npm install -g mean-cli
$ mean init meantest
$ cd meantest && npm install
$ vi config/env/development.js
〜〜〜
debug: 'true',
hostname: '0.0.0.0', // 追加する
mongoose: {
〜〜〜
$ node server
如果不设置主机名,会出现以下错误,请添加’0.0.0.0’。
Mean app started on port 3000 (development)
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
其他
可以使用grunt启动,但会出现错误。
$ sudo npm install -g grunt-cli
$ cd meantest
$ grunt
下面的错误发生了。
Running "clean:0" (clean) task
Running "jshint:all" (jshint) task
packages/system/app.js
10 |var System = new Module('system');
^ Redefinition of 'System'.
>> 1 error in 47 files
Warning: Task "jshint:all" failed. Use --force to continue.
如果将packages/system/app.js中的System更改为_system解决了问题,但还有其他更好的方法吗…?
'use strict';
/*
* Defining the Package
*/
var Module = require('meanio').Module,
favicon = require('serve-favicon'),
express = require('express');
var _system = new Module('system');
/*
* All MEAN packages require registration
* Dependency injection is used to define required modules
*/
_system.register(function(app, auth, database) {
//We enable routing. By default the Package Object is passed to the routes
_system.routes(app, auth, database);
_system.aggregateAsset('css', 'common.css');
// The middleware in config/express will run before this code
// Set views path, template engine and default layout
app.set('views', __dirname + '/server/views');
// Setting the favicon and static folder
app.use(favicon(__dirname + '/public/assets/img/favicon.ico'));
// Adding robots and humans txt
app.use(express.static(__dirname + '/public/assets/static'));
return _system;
});