How to create a Directory Folder by using postman Javascript?

Viewed 43

How to create a Directory Folder by using postman??

Any suggestion/idea would be much appreciated.

1 Answers

Ok - I dont really get the intet of this question. However here is the solution I would suggest on the given information:

When sending a request with Postman you first need a node.js app running in the background. I just build a simple app that will consume a POST request and create a directory from it:

const express = require('express');
const fs = require('fs');
const app = express();
const port = 5000;

app.use(express.json());

app.post('/createDir', async(req, res) => {
    const dir = req.body.directory;
    try {
        if(!fs.existsSync(dir)){
            fs.mkdirSync(dir, {recursive: true});
            res.send('Folder created');
        } else {
            res.send('Folder is already existing');
        }
    } catch (err) {
        console.error(err);
        res.status(500).json({
            err: 'Something went wrong'
        });
    }
})


app.listen(port, () => {
    console.log(`Listening on port ${port}`);
});

After starting the app, you then can send a POST request using postman: enter image description here

And there you have it: enter image description here

enter image description here

Related