LoginSignup
19
18

More than 5 years have passed since last update.

Vagrantで起動したCentOSにmean環境構築して起動まで

Last updated at Posted at 2014-10-29

mean.ioに書いてある手順だけではすんなりとはいかなかったので、自分用にメモ

参考

環境情報

対象 バージョン
CentOS 6.6
NodeJS 0.10.33
NPM 1.4.28
MongoDB 2.6.5
mean-cli 0.4.0

事前作業

VagrantでCentOS6を立ち上げておく

$ sudo yum update -y

Gitのインストール

$ sudo yum install -y git

MongoDBのインストール

$ sudo vi /etc/yum.repos.d/mongodb.repo
/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

mean環境の作成と実行

$ sudo npm install -g mean-cli
$ mean init meantest
$ cd meantest && npm install
$ vi config/env/development.js
config/env/development.js
〜〜〜
debug: 'true',
hostname: '0.0.0.0', // 追加する
mongoose: {
〜〜〜
$ node server

※ hostnameを設定しないと、下記エラーがでたので、'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とかに変更したら解消したが、他に良い方法はないのか・・・。

packages/system/app.js
'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;
});
19
18
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18