[express]라우터 만들고 postman 에서 연결 됬는지 확인하는법

susu.J·2021년 1월 18일
0

app.js

import express from 'express';
import mongoose from 'mongoose';
import config from'./config';
import hpp from "hpp";
import helmet from 'helmet';
import cors from 'cors';

//Routes
import postsRoutes from './routes/api/post';
import morgan from 'morgan';

const app = express();
const {MONGO_URI} = config;

 app.use(hpp());
 app.use(helmet());

 app.use(cors({ origin: true, credentials: true }));
 app.use(morgan("dev"))

 app.use(express.json());


mongoose
    .connect(MONGO_URI, {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useCreateIndex: true,
    })
    .then(()=> console.log("MongoDB connecting Success!!"))
    .catch((e)=> console.log(e));


//use routes
app.get("/");
app.use('/api/post', postsRoutes);

export default app;

app.use('api/post', postsRoutes)
이렇게 연결해주었고, 이제 포스트맨에서 확인해볼텐데

확인하기 전에 models/post.js 에서 보면
title과 contents 를 required: true를 해놨기 때문에 반드시 넣어야한다.

title과 contents를 넣어 post로 보내본다

profile
on the move 👉🏼 https://sjeong82.tistory.com/

0개의 댓글