参考記事のmongodb操作用のmongo.jsを追加
について、どのディレクトリに配置するのが適当なのかお尋ねしたいです。
現在のディレクトリ構成は以下です。
. ├── app.js ├── bin │ └── www ├── mongo.js ├── node_modules ├── package-lock.json ├── package.json ├── public │ ├── images │ ├── javascripts │ └── stylesheets │ └── style.css ├── routes │ ├── index.js │ └── users.js └── views ├── error.ejs └── index.ejs
参考記事内でのコードは以下です。
/** * node-mongodbのドキュメント * http://mongodb.github.io/node-mongodb-native/2.1/ */ var db; var MongoClient = require('mongodb').MongoClient; var assert = require('assert'); // Connection URL var url = 'mongodb://localhost:27017/Sakepedia'; // Use connect method to connect to the Server MongoClient.connect(url, function(err, mongodb) { assert.equal(null, err); console.log("Connected correctly to server"); db = mongodb; }); var collection = function( name ) { return db.collection( name ); } module.exports = collection;
このコードをどこのディレクトリに格納すれば良いか迷っています。
nodejs
を始めたばかりで、初歩的な質問かもしれませんが、
ご教授いただけ方、よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/11/08 02:25