0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cookie取得

Posted at
const express = require('express');
const cookieParser = require('cookie-parser');

const app = express();

// cookie-parserミドルウェアを使用
app.use(cookieParser());

// ルートでCookieの値を取得
app.get('/', (req, res) => {
    // クライアントから送られたCookieを取得
    const cookies = req.cookies;

    // Cookieの特定の値を取得(例: "user"というキーの値)
    const user = cookies.user;

    // レスポンスを送信
    res.send(`Cookieの値: ${JSON.stringify(cookies)}, user: ${user}`);
});

// サーバーの起動
const PORT = 3000;
app.listen(PORT, () => {
    console.log(`サーバーがポート${PORT}で起動しました`);
});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?