Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Rest Api to clone repository from git

I tried to do it but I gave up… yeaIs it possible to when you call example, https:api.domain.com/createfile/(+ data) it creates a file in that server in folder I want to if so how?

It’s a javascript file that I want also make work and start process of it. (npm run) it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming that you have root access on your server.

Initialization steps:

  1. Install node.js on your machine
  2. Create a new node project and install Express npm install express should do the trick
  3. Setup a basic http server and now you must make decisions on how to field the requests
    1. If you plan to run everything over regular http then you can probably just have the node server listen on port 80 of your machine. (Really should run https)
    2. If you want to run https (and thus have a domain name) then I would take the time to setup nginx to listen to port 80 (to redirect to 443) and 443 (TLS port) and then have it serve as a reverse proxy for the express server. Thus the node server could just run on localhost:3000 for example. (If you want a free certificate for SSL you can use let's encrypt with nginx)
    3. My Suggestion: Use nginx as a reverse proxy either way
  4. Setup your request endpoint, a post request endpoint for example.
  5. There are a few ways to clone a repo through node, using shelljs is one way.

What the express server may look like by now:

const express = require('express');
const shell = require('shelljs')
const app = express();

app.post('/createfile/:data', async function (req, res) {
    if (!req || !req.params || !req.params.data ) {
        return res.status(400).send("Malformed url");
    }
    // I assume the data in the paramas is the url to the git repo
    const giturl = req.params.data;

    // You should probably lightly check the url to make sure its a valid one on the surface level.
    
    const path = 'absolute/path/to/folder'
    
    if (!shell.which('git')) {
        shell.echo('Sorry, this script requires git');
        shell.exit(1);
        return res.status(400).send("Not supported");
    }

    shell.cd(path)
    shell.exec('git clone ' + giturl, function (code, stdout, stderr) {
       console.log('Exit code:', code);
       console.log('Program output:', stdout);
       console.log('Program stderr:', stderr);
       if (code === 0)
           return res.status(200).send("Success");
       else
           return res.status(400).send("Issue with clone")
    });
});

const server = await app.listen(3000);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!