0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

npmでmongodbとサーバーを同時起動

Posted at

mongodbを起動するのがめんどくさい。
サービス登録しておけよって話はおいといて、同時に起動したかった。

やってみた

必要なのはconcurrentlyモジュール

npm install concurrently --save 

サンプルとしてサーバ側はこんな感じ

server.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('server start!\n');
}).listen(3000, '127.0.0.1');

package.jsonのスクリプトでこんな風に記述すればOK

package.json
{
  "name": "testApp",
  "main": "index.js",
  "scripts": {
    "start": "concurrently  \"mongod --dbpath ./data --logpath ./log/log.txt\" \"node server.js\" "
  },
  "dependencies": {
    "concurrently": "^3.5.0"
  }
}

npm startを実行するとmongoとサーバが立ち上がる。

0
2
0

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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?