[node.js] 초간단 api 서버 샘플코드

By | 7월 6, 2022

환경

  • node 16.15.1


package.json

{
  "name": "test-mock-server",
  "main": "app.js",
  "packageManager": "yarn@3.2.1",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.18.1"
  }
}


app.js

var express = require("express");
var cors = require("cors");
var app = express();

app.listen(4000, () => {
  console.log("Server running on port 4000");
});

app.use(cors());

app.get("/testList", (req, res, next) => {
  res.json({
    data: {
      list: [
        {
          no: 1,
          name: "Inga",
          city: "Izmail",
          price: 39757,
        },
        {
          no: 2,
          name: "Janna",
          city: "Shillong",
          price: 85111,
        },
        {
          no: 3,
          name: "Garrison",
          city: "Ghanche",
          price: 54681,
        }
      ],
    },
  });
});     


서버 기동

  • node app.js
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments