0
Every time I open the route "/" says finAll is not a function
, what is wrong?
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)
})
Content of 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
}
Content of 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 } )
Can inform the code of your file
./models/Post
?– Sorack
https://pastebin.com/UB0TZ7Z0
– Gabriel
https://pastebin.com/juMZU3aS
– Gabriel
Do not put to Pastebin. Add to your question, otherwise it is incomplete and runs the risk of being closed due to lack of information
– Sorack
It’s just that I lent my network adapter to my friend just for today and the internet isn’t picking up, and then I’m using the stack by cell phone and I can’t format texts :/
– Gabriel
No problem, paste in the answer I format
– Sorack
But can you tell which error? I guarantee nn is the internet, because I installed all the necessary packages
– Gabriel
All right, hold on
– Gabriel
const Sequelize = require('sequelize') const sequelize = new Sequelize( "Friendship", "root", ", { host: "localhost", dialect: "mysql" }) // Post.Sync( { force: true } ) module.Exports = { Sequelize: Sequelize, sequelize: sequelize } ~
– Gabriel
const db = require('. /db') const Post = db.sequelize.define("posts", { title: { type: db.Sequelize.STRING }, content: { type: db.Sequelize.TEXT } // Post.Sync( { force: true } )
– Gabriel
Edit the question and stick to it
– Sorack
it’s all going together I don’t know why, want to wait until tomorrow until I get my adapter?
– Gabriel
wait a second
– Gabriel
There you go, there you go
– Gabriel