从Stack Exchange导入JSON文件并使用Node.js打印(Express)涉及到几个关键概念:
以下是一个简单的示例代码,展示如何从Stack Exchange API获取JSON数据并使用Express打印:
const express = require('express');
const axios = require('axios');
const app = express();
const port = 3000;
app.get('/stack-data', async (req, res) => {
try {
const response = await axios.get('https://api.stackexchange.com/2.3/questions?site=stackoverflow');
const data = response.data;
console.log(data);
res.send(data);
} catch (error) {
console.error(error);
res.status(500).send('Error fetching data from Stack Exchange API');
}
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
JSON.parse()
方法。通过以上步骤和示例代码,你应该能够成功从Stack Exchange导入JSON文件并使用Node.js和Express打印数据。
领取专属 10元无门槛券
手把手带您无忧上云