Skip to content

Instantly share code, notes, and snippets.

@butaji
Created November 29, 2020 15:11
Show Gist options
  • Save butaji/6c67281fceee2cf5bb24412ddc1afef7 to your computer and use it in GitHub Desktop.
Save butaji/6c67281fceee2cf5bb24412ddc1afef7 to your computer and use it in GitHub Desktop.
Вечерний Сниппет (node.js)
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.get('/api', (req, res) => {
let files = list()
res.send({
files: files
})
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
const fs = require('fs');
// directory path
const dir = './node_modules/';
function list() {
// list all files in the directory
var arr = []
try {
const files = fs.readdirSync(dir);
// files object contains all files names
// log them on console
files.forEach(file => {
arr.push(file);
});
} catch (err) {
console.log(err);
}
return arr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment