const express = require('express')
const app = express()
const fetch = require('node-fetch');
const url = "https://jsonplaceholder.typicode.com/users";
let users = [];
function getUsers(url) {
const user = fetch(url)
.then((res) => {
res.json().then((res1) => {
users = res1;
})
})
};
const filterUser = (req,res) => {
const filteredUser = users.filter(user => user.name.toLowerCase().startsWith('ka'))
let fresults = res.json(filteredUser)
return fresults;
}
app.get('/', (req, res) => {
res.send(users)
})
app.listen(3000, () => {
console.log("listening on port 3000");
getUsers(url)
})
字符串
从https://jsonplaceholder.typicode.com/users获取用户数据的url,并从用户名'Ka'开始过滤用户,并打印输出列表
1条答案
按热度按时间7xllpg7q1#
您需要获取用户并将其过滤掉。您没有在任何端点中调用它
字符串