Ich mache derzeit eine React, Express, Massivejs, postgreSql App. Ich bekomme den Fehler "TypeError: db.createList ist keine Funktion", wenn ich versuche, meinen Post-Endpunkt zu treffen. Ich bin nicht sicher, wie ich es beheben soll, da es richtig aussieht.Getting "TypeError: db.createList ist keine Funktion"
Meine Dateistruktur:
sieht Mein Server-Datei wie folgt:
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); });
Mein Controller sieht wie folgt aus:
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);
}
})
}
}
Meine createList.sql Datei aussieht so:
INSERT INTO list (
name
)
VALUES (
$1
);
Haben Sie die Datei "createlist.sql" oder "createList.sql" benannt? –
Falsches Bild tut mir leid. Aber ich nannte es createList.sql. –