server 만들기

유관희·2022년 9월 20일
0
const express = require('express')
const app = express()
const bodyParser = require('body-parser')

app.use(bodyParser.json()) // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded


let id = 2;

const todoList =[
    {
        id:1,
        text:'할 일',
        done: false,
    }
]


app.get('/api/todo', (req, res)=>{
    res. json(todoList);
});

app.post('/api/todo',(req,res)=>{
    const { text, done} = req.body;
    todoList.push({
        id: id++,
        text,
        done,
    });
    return res.send('SUCCESS');
})

app.listen(3000,()=>{
    console.log("server start!");
})

실행 : node app.js
post 실행은 postman에서 확인
http://localhost:3000/api/todo
참고 사이트
http://expressjs.com/en/5x/api.html#req.body

COR 정책에 막혔을 때 해결하는 법
https://www.npmjs.com/package/cors

$ npm install cors

const express = require('express')
const cors = require('cors')
const app = express()
 
app.use(cors())
 
app.get('/products/:id', function (req, res, next) {
  res.json({msg: 'This is CORS-enabled for all origins!'})
})
 
app.listen(80, function () {
  console.log('CORS-enabled web server listening on port 80')
})
profile
안녕하세요~

9개의 댓글

comment-user-thumbnail
2025년 2월 26일

This really which means delightful not to mention original. I just absolutely adore typically the styles not to mention anyone who will become it again in your mailing could be cheerful. Fitness Coach Winter Park FL

답글 달기
comment-user-thumbnail
2025년 3월 9일

Thanks a ton to get writing this sort of superb posting! I uncovered your web blog ideal for this demands. Contained in the grapefruit excellent plus handy discussions. Keep up to date favorable deliver the results! 用賀英会話

답글 달기
comment-user-thumbnail
2025년 3월 9일

With thanks to get furnishing recently available posts in connection with the dilemma, I actually look ahead to learn extra. jfm radio online

답글 달기
comment-user-thumbnail
2025년 3월 10일

It is a great suggestions specifically to be able to people not used to blogosphere, quick and also correct information… Thank you regarding revealing this place. A necessity examine write-up. 파주 사업자 대출

답글 달기
comment-user-thumbnail
2025년 3월 26일

Outstanding submit, travelled in advance and also book marked your internet site. My partner and i can’t hold out to learn a lot more coming from an individual. https://www.clusterrepairsuk.co.uk/

답글 달기
comment-user-thumbnail
2025년 3월 30일

You could be allowed to put up manufacturers, except for shortcuts, in the event that they've been recognized not to mention concerning content. 大和高田 ヘルニア

답글 달기
comment-user-thumbnail
2025년 4월 3일

Truly My spouse and i go through the idea recently nevertheless I had created a number of views over it and from now on I want to you just read the idea yet again since it is rather well crafted. capture of field sales information in real-time

답글 달기
comment-user-thumbnail
2025년 4월 3일

This specific is a great article My spouse and i witnessed due to talk about the idea. It is definitely precisely what I want to to view expect throughout potential you can proceed pertaining to expressing a real exceptional article. parawan pokojowy

답글 달기
comment-user-thumbnail
2025년 4월 7일

This is simply the info I'm discovering almost everywhere. Many thanks for the weblog, I simply sign up your site. This can be a good weblog. inch. 本八幡 英会話

답글 달기

관련 채용 정보