Skip to content

Commit

Permalink
added files
Browse files Browse the repository at this point in the history
  • Loading branch information
jagadeeshmarthy authored Nov 28, 2019
1 parent f76a5ba commit a8cae4b
Show file tree
Hide file tree
Showing 5 changed files with 1,711 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
uploads
5 changes: 4 additions & 1 deletion README.md
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
47 changes: 47 additions & 0 deletions app.js
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}===`)
})
Loading

0 comments on commit a8cae4b

Please sign in to comment.