var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var pg = require('pg');
var routes = require('./../routes/index');
var users = require('./../routes/users');
var connectionString = process.env.DATABASE_URL ||'postgres://postgres:PSWR@localhost:5435/ProjetoCliente';
var client = new pg.Client(connectionString);
client.connect();
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
meu DAO
var client = require('express');
var nome, rg, cpf;
function UserDAO() {
}
UserDAO.prototype.criar = function (nome, rg, cpf) {
client.query('insert into clientes (nome, rg, cpf) values($1, $2, $3)',
[nome, rg, cpf])
}
UserDAO.prototype.deletar = function (id) {
client.query('delete from clientes where id=$1',
[id])
}
UserDAO.prototype.update = function (id) {
client.query('update from clientes set nome=$1 ,rg=$2, cpf=$3 where id=$4',
[nome, rg, cpf, id])
}
module.exports = function () {
return UserDAO;
}
meu test pro DAO
var ClientDAO = require('../DAOS/UsuarioDAO')();
new ClientDAO().criar('teste','teste','teste');
o erro
var opts = Object.create(options || null);
^
TypeError: Object prototype may only be an Object or null: insert into clientes (nome, rg, cpf) values($1, $2, $3)
at Function.query (C:\Users\Gustavo\IdeaProjects\nodeapp\node_modules\express\lib\middleware\query.js:25:21)
at UserDAO.criar (C:\Users\Gustavo\IdeaProjects\nodeapp\DAOS\UsuarioDAO.js:10:12)
at Object.<anonymous> (C:\Users\Gustavo\IdeaProjects\nodeapp\DAOS\test.js:6:17)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:352:7)
sabem o que poe ser? fico grato por qualquer ajuda