0
私が使用しようとnodejsにcaminteJs
を実装するよ、私はmodels
フォルダを作成し、その中で私はindex.js
にNodejsは
user.js //contains user table schema
news.js //contains news table schema
として分離したファイルの中に包まれた、いくつかのデータベーススキーマを持っているのを
var users = require('./user');
var news = require('./news');
module.exports = {
users:users,
news:news
};
user.js
ファイルの内容::
models
フォルダに
config.js
ファイルの内容:
var caminte = require('caminte'),
Schema = caminte.Schema,
config = {
driver: "mysql",
host: "localhost",
port: "3306",
username: "root",
password: "",
database: "test",
pool: true
},
schema = new Schema(config.driver, config);
module.exports = {
caminte: caminte,
Schema: Schema,
config: config,
schema: schema
}
、その後、私のserver.js
それらを使用する:
var socket = require('socket.io'),
...
config = require('./config'),
models = require('./models');
server.listen(port, function() {
console.log('Server listening at port %d', port);
});
io.on('connection', function (socket) {
socket.on("new_channel", function (data, device) {
new models.channels({ channel_name: 'Peter' });
console.log(channel);
});
});
私はuser.js
に、このエラーを取得する:
TypeError: schema.define is not a function
おかげで、問題が解決します –