-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f76a5ba
commit a8cae4b
Showing
5 changed files
with
1,711 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
uploads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
# monoceptTask | ||
# monoceptTask | ||
Clone the repository | ||
Install dependencies - npm i | ||
Run the app - node app.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
const express = require('express'); | ||
const request = require('request'); | ||
const rp = require('request-promise'); | ||
const fs = require('fs'); | ||
const multer = require('multer'); | ||
|
||
const app = express(); | ||
const upload = multer({ dest: 'uploads/' }); | ||
const gitUrl = 'https://api.github.com/users/'; | ||
const PORT = '3000'; | ||
|
||
//api route to get the repos for user | ||
app.post('/getRepos', upload.any(), async (request, response) => { | ||
var fileData = fs.readFileSync(request.files[0].path, 'utf8'); | ||
var users = fileData.toString().split(","); | ||
var obj = {}; | ||
var result; | ||
try { | ||
for (let i = 0; i < users.length; i++) { | ||
result = await getUserRepos(users[i]); | ||
obj[users[i]] = result.map(data => data.url); | ||
} | ||
// await fs.unlinkAsync(req.file.path) | ||
response.status(200).send(obj); | ||
} | ||
catch(e) { | ||
response.status(500).send(e); | ||
} | ||
}) | ||
|
||
// calls github api for mentioned user | ||
async function getUserRepos(user) { | ||
var options = { | ||
method: 'GET', | ||
json: true, | ||
uri: gitUrl + user + "/repos", | ||
headers: { | ||
'user-agent': 'node.js' | ||
} | ||
}; | ||
return rp(options); | ||
} | ||
|
||
app.listen(PORT, () => { | ||
console.log(`==app is listening at ${PORT}===`) | ||
}) |
Oops, something went wrong.