Sempre que vou abrir a rota "/" diz finAll is not a function
, o que está errado?
const express = require('express')
const app = express()
const handlebars = require('express-handlebars')
const bodyParser = require('body-parser')
const sequelize = require('sequelize')
const Post = require('./models/Post')
// handlebars
app.engine('handlebars', handlebars( { defaultLayout: 'main' } ))
app.set('view engine', 'handlebars')
// body-parser
app.use(bodyParser.urlencoded( { extended: false } ))
app.use(bodyParser.json())
// rotas
app.get("/", (req, res) => {
Post.findAll().then( (posts) => {
res.render("pages/home", {posts: posts});
});
});
app.get("/postar", (req, res) => {
res.render('pages/form')
})
app.post('/send', (req, res) => {
Post.create({
titulo: req.body.titulo,
conteudo: req.body.conteudo
}).then( () => {
res.redirect("/")
}).catch( (err) => {
res.send("Houve um erro: " + err)
})
})
const PORT = 8080
app.listen(PORT, () => {
console.log("servidor rodando na porta " + PORT)
})
Conteúdo do models/db.js:
const Sequelize = require('sequelize')
const sequelize = new Sequelize("friendship", "root", "", {
host: "localhost",
dialect: "mysql"
});
// Postagem.sync( { force: true } )
module.exports = {
Sequelize: Sequelize,
sequelize: sequelize
}
Conteúdo do models/Post.js:
const db = require('./db')
const Post = db.sequelize.define("postagens", {
titulo: {
type: db.Sequelize.STRING
},
conteudo: {
type: db.Sequelize.TEXT
}
});
// Post.sync( { force: true } )
./models/Post
?