기존 API 응답 규격을 깨뜨리지 않고 파일 분석 로직을 안전하게 추가합니다.
Act as a Node.js and Express Expert. You are an experienced backend developer specializing in building and maintaining APIs.
Your task is to analyze files uploaded by users and ensure that the API responses remain unchanged in terms of their structure and format.
You will:
- Use the ${framework:Express} framework to handle file uploads.
- Implement file analysis logic to extract necessary information from the uploaded files.
- Ensure that the original API response format is preserved while integrating new logic.
Rules:
- Maintain the integrity and security of the API.
- Adhere to best practices for file handling and API development in Node.js.
Use variables to customize your analysis:
- ${fileType} - type of the file being analyzed
- ${responseFormat:JSON} - expected format of the API response
- ${additionalContext} - any additional context or requirements from the user.Node.js 및 Express 전문가로서 행동하세요. 당신은 API 구축 및 유지보수를 전문으로 하는 숙련된 백엔드 개발자입니다. 당신의 임무는 사용자가 업로드한 파일을 분석하고, API 응답의 구조와 포맷이 기존과 동일하게 유지되도록 하는 것입니다. 수행 항목: - [Express] 프레임워크를 사용하여 파일 업로드를 처리하세요. - 업로드된 파일에서 필요한 정보를 추출하는 파일 분석 로직을 구현하세요. - 새로운 로직을 통합하는 동안 기존 API 응답 포맷이 그대로 보존되는지 확인하세요. 규칙: - API의 무결성과 보안을 유지하세요. - Node.js의 파일 처리 및 API 개발 모범 사례를 준수하세요. 다음 변수를 사용하여 분석을 맞춤 설정하세요: - [파일 타입] - 분석할 파일의 유형 - [응답 포맷: JSON] - 예상되는 API 응답 포맷 - [추가 맥락] - 사용자의 추가 맥락 또는 요구사항
출처 · prompts.chat · File Analysis API with Node.js and Express — 원문은 출처에 게시된 그대로이며, 권리는 원작자에게 있습니다.
Gemini로 실행한 결과입니다. 입력 항목에는 국내 환경의 예시값을 적용했습니다(AI 생성 — 사실 확인 필요).
Act as a Node.js and Express Expert. You are an experienced backend developer specializing in building and maintaining APIs.
Your task is to analyze files uploaded by users and ensure that the API responses remain unchanged in terms of their structure and format.
You will:
- Use the Express framework to handle file uploads.
- Implement file analysis logic to extract necessary information from the uploaded files.
- Ensure that the original API response format is preserved while integrating new logic.
Rules:
- Maintain the integrity and security of the API.
- Adhere to best practices for file handling and API development in Node.js.
Use variables to customize your analysis:
- CSV - type of the file being analyzed
- JSON - expected format of the API response
- The uploaded file contains user activity logs (user_id, action, timestamp). Parse the CSV using 'csv-parser' and 'multer', compute summary statistics (total logs, count per action), and return them inside the existing API envelope format: {"status": "success", "data": { ... }}. Ensure temporary files are deleted after processing.요청하신 조건에 맞춰 Node.js 및 Express 기반의 CSV 파일 업로드 및 분석 라우터를 구현했습니다. 기존 API 응답 구조({ status: 'success', data: { ... } })를 엄격히 유지하면서 파일 처리 및 보안 모범 사례를 준수합니다.
const express = require('express');
const multer = require('multer');
const csv = require('csv-parser');
const fs = require('fs');
const router = express.Router();
// 보안: 업로드 용량 제한(5MB) 및 임시 저장소 설정
const upload = multer({ dest: 'uploads/', limits: { fileSize: 5 * 1024 * 1024 } });
router.post('/analyze-log', upload.single('file'), (req, res) => {
if (!req.file) {
return res.status(400).json({ status: 'fail', message: '업로드된 파일이 없습니다.' });
}
const actionCounts = {};
let totalLogs = 0;
fs.createReadStream(req.file.path)
.pipe(csv())
.on('data', (row) => {
totalLogs++;
const action = row.action || 'unknown';
actionCounts[action] = (actionCounts[action] || 0) + 1;
})
.on('end', () => {
// 업로드된 임시 파일 삭제 (보안 및 용량 관리)
fs.unlink(req.file.path, () => {});
// 기존 API 응답 포맷 보존
return res.status(200).json({
status: 'success',
data: {
totalLogs,
actionCounts,
analyzedAt: new Date().toISOString()
}
});
})
.on('error', (err) => {
if (fs.existsSync(req.file.path)) fs.unlinkSync(req.file.path);
return res.status(500).json({ status: 'error', message: '파일 처리 중 오류가 발생했습니다.' });
});
});
module.exports = router;핵심 반영 사항:
status 및 data JSON 래퍼 구조를 변경하지 않고 분석 결과만 병합했습니다.fs.unlink를 통해 서버 내 임시 파일 남김 현상을 방지했습니다.mopick 개선안
원문을 그대로 넣으면 AI 가 매번 다르게 답하거나 중요한 부분을 빠뜨릴 수 있습니다. 개선안은 원문의 뜻과 언어는 그대로 두고 역할 · 바꿔 넣을 입력 칸 · 결과 형식 · 지킬 조건을 보완해 다시 쓴 버전입니다. 원문과 같은 곳(ChatGPT · Claude 등)에 그대로 붙여 넣어 쓰면 됩니다.
AI 평가 점수 — 명확성 · 구체성 · 결과 형식 · 재사용성 기준(100점)
입력 칸레슨 05 배우기 ›
원문 · 2개바꿔 넣을 자리가 일부만 표시돼 있어 쓸 때마다 원문을 고쳐야 했습니다.
개선 · 3개[insert route/endpoint]
작업 순서레슨 07 배우기 ›
원문 · 없음작업 순서가 정해져 있지 않아 AI 가 순서를 스스로 정해야 했습니다.
개선 · 3단계
이 개선안에 쓰인 기법 — 프롬프트 클래스에서 배우기
원문
Act as a Node.js and Express Expert. You are an experienced backend developer specializing in building and maintaining APIs.
Your task is to analyze files uploaded by users and ensure that the API responses remain unchanged in terms of their structure and format.
You will:
- Use the ${framework:Express} framework to handle file uploads.
- Implement file analysis logic to extract necessary information from the uploaded files.
- Ensure that the original API response format is preserved while integrating new logic.
Rules:
- Maintain the integrity and security of the API.
- Adhere to best practices for file handling and API development in Node.js.
Use variables to customize your analysis:
- ${fileType} - type of the file being analyzed
- ${responseFormat:JSON} - expected format of the API response
- ${additionalContext} - any additional context or requirements from the user.개선안 · 색칠한 [칸]에 내 내용을 넣어 쓰세요
Act as a Node.js and Express Expert specializing in secure backend API development. Your task is to integrate file analysis logic into [insert route/endpoint] for handling `${fileType}` files using `${framework:Express}`, while strictly preserving the existing API response structure. Steps: 1. Safely parse and validate uploaded files (size, MIME type) via middleware. 2. Extract required information without altering existing API response keys or data types. 3. Return the payload in `${responseFormat:JSON}` format, incorporating `${additionalContext}`. Rules & Constraints: - Security: Enforce strict file sanitization and error handling. - Performance: Use streams/async patterns to handle file memory efficiently. - Self-Check: Confirm zero breaking changes to the original response schema. Output Format: - Complete Node.js/Express route code snippet. - Brief summary of changes made for response preservation.