0
現在、React、Express、Massivejs、postgreSqlアプリケーションを実行しています。私は "TypeError:db.createListは関数ではありません"というエラーが出ています。いつでも私のポストエンドポイントにヒットしようとしています。正しいと思われるので、どのように修正するのか分かりません。「TypeError:db.createListが関数ではありません」
マイファイル構造:
私のサーバーのファイルは次のようになります。
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
var massive = require("massive");
var connectionString = 'postgress://[email protected]/todo';
var massiveInstance = massive.connectSync({connectionString : connectionString})
var config = require('./config.js');
var app = module.exports = express();
app.set('db', massiveInstance);
var listCtrl = require('./controller/listCtrl.js');
// **************** Middleware ****************
app.use(express.static(__dirname + './../public'));
app.use(bodyParser.json());
// ****************** Endpoints ***************
app.post('/api/add/list', listCtrl.createList);
app.get('/api/get/list', listCtrl.createList);
app.get('*', function(req, res) {
res.sendFile('index.html', { root: './public'});
})
app.listen(config.port, function() { console.log('Server initiated on port', config.port); });
私のコントローラは次のようになります。
var app = require('../server.js');
var db = app.get('db');
module.exports = {
createList: function(req, res, next) {
console.log('db'my);
db.createList([req.body.name], function(err, res) {
res.status(200).send('List created');
})
},
readList: function(req, res) {
db.readList(function(err, res) {
if (err) {
console.log("readList failed");
} else {
console.log("readList working " + req.body, req.params);
}
})
}
}
マイcreateList.sqlファイルルックスこのように:
INSERT INTO list (
name
)
VALUES (
$1
);
ファイル名を「createlist.sql」または「createList.sql」としましたか? –
イメージが間違っています。しかし、私はそれをcreateList.sqlという名前にしました。 –