## 流程
- 連接 mongodb
- 建立 koa 連線
- 建立API查詢 ID 或名稱取得資料
- 填權息成功率
- 除權息次數
- 填權息次數
- 統計年分
- 歷年平均現金殖利率
- 歷年平均還原殖利率
{
"name": "api-stock-dividend-yield",
"version": "1.0.0",
"description": "提供股票的API查詢資料,例如:填權息成功率、除權息次數、填權息次數、統計年分、歷年平均現金殖利率、歷年平均還原殖利率",
"main": "index.js",
"scripts": {
"test": "echo ok"
},
"repository": {
"type": "git",
"url": "git+https://github.com/luckstar77/api-stock-dividend-yield.git"
},
"keywords": [
"TAIWAN",
"STOCK",
"DIVIDEND",
"YIELD"
],
"author": "Allen Lai",
"license": "MIT",
"bugs": {
"url": "https://github.com/luckstar77/api-stock-dividend-yield/issues"
},
"homepage": "https://github.com/luckstar77/api-stock-dividend-yield#readme"
}
"dependencies": {
"express": "^4.18.1",
"mongodb": "^4.10.0"
},
"devDependencies": {
"@types/node": "^18.8.2",
"eslint": "^8.24.0"
}
import express from "express"
const app = express()
app.get('/stock', function (req, res) {
const { search } = req.query
res.send('Hello World')
})
app.listen(3000)
{
"editor.codeActionsOnSave": {
"source.fixAll": true
}
}
import express from 'express';
import { connect as mongodbConnect } from './db/mongodb';
const COLLECTION = 'stock';
(async ()=> {
const mongodbClient = await mongodbConnect();
const app = express();
app.get('/stock', async function (req, res) {
const { search } = req.query;
const stock = await mongodbClient.collection(COLLECTION).findOne({
$or:[{id: search},{name: search}]
});
res.send(stock);
});
app.listen(3000);
})();