게시글 불러오기
limit & offset 방식
//limit & offset 방식의 infiniti scrolling
const express = require("express");
const { Post } = require("../models/");
const router = express.Router();
router.get("/", async (req, res, next) => {
try {
//DB여러개 가져올떄
const posts = await Post.fingAll({
limit: 10, //10개만 가져와라
offset: 10, //11~20만큼 가져와라
order: [["createdAt", "DESC"]], //늦게 생성된 순서로
});
res.status(200).json(posts);
} catch (e) {
console.error(e);
next(e);
}
});limit & Lastid
Last updated