数据库中"/>
我如何将json数据添加到node.js中的mysql数据库中
我要从;
我想用json数据中的id,名称,用户名和电子邮件填充mysql数据库。我正在使用一个名为“ request”的节点模块来读取在线json api
const db = mysql.createConnection({ host: 'localhost', user: 'root', password: '', database: 'nodemysql' }); connect db.connect((err) => { if (err) { throw err } console.log('MySql Connected...'); }); app.get('/populate', (req, res) => { request({ url: "", json: true }, (err, res, body) => { res.send(body); }); })
这是json API中项目的两个示例
{ "id": 1, "name": "Leanne Graham", "username": "Bret", "email": "[email protected]", "address": { "street": "Kulas Light", "suite": "Apt. 556", "city": "Gwenborough", "zipcode": "92998-3874", "geo": { "lat": "-37.3159", "lng": "81.1496" } }, "phone": "1-770-736-8031 x56442", "website": "hildegard", "company": { "name": "Romaguera-Crona", "catchPhrase": "Multi-layered client-server neural-net", "bs": "harness real-time e-markets" } }, { "id": 2, "name": "Ervin Howell", "username": "Antonette", "email": "[email protected]", "address": { "street": "Victor Plains", "suite": "Suite 879", "city": "Wisokyburgh", "zipcode": "90566-7771", "geo": { "lat": "-43.9509", "lng": "-34.4618" } }, "phone": "010-692-6593 x09125", "website": "anastasia", "company": { "name": "Deckow-Crist", "catchPhrase": "Proactive didactic contingency", "bs": "synergize scalable supply-chains" } }
我只需要将id,名称,用户名和电子邮件添加到mysql数据库中,作为每个用户的行的列
我要从,我想用json数据中的id,名称,用户名和电子邮件填充mysql数据库。我正在使用一个名为...
回答如下:假设
更多推荐
我如何将json数据添加到node.js中的mysql数据库中
发布评论