feat(file-stat): initial commit

This commit is contained in:
dancingCycle 2022-06-06 11:56:15 +02:00
parent 7a64523e34
commit f7de6852aa
6 changed files with 86 additions and 0 deletions

1
file-stat/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env*

21
file-stat/README.md Normal file
View File

@ -0,0 +1,21 @@
## Overview
Get file statistics
## Preparation
Run the following command in your favorite terminal to install dependenies.
```
npm i
```
## Development setup
Run the following command in your favorite terminal if you fancy log messages for debugging.
```
export DEBUG=$DEBUG,debug
```
Run the following command in your favorite terminal to start the service in development mode.
```
npm run dev
```

View File

@ -0,0 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Stefan Begerad <stefan@begerad.de>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

30
file-stat/file-stat.js Normal file
View File

@ -0,0 +1,30 @@
const debug=require('debug')('last-modified');
const fs = require('fs');
function getMTimeAsync(fileName){
let mtime=fs.stat(fileName, (err, stats) => {
if(err) {
throw err;
}
return stats.mtime;
});
debug('mtime: '+mtime);
return mtime;
}
function getMTimeSync(fileName){
let mtime=null;
try {
const stats = fs.statSync(fileName);
mtime=stats.mtime;
} catch (error) {
console.log(error);
}
debug('mtime: '+mtime);
return mtime;
}
module.exports={
getMTimeAsync,
getMTimeSync
};

8
file-stat/index.js Normal file
View File

@ -0,0 +1,8 @@
const debug=require('debug')('debug');
const fs = require('fs');
const fileStat=require('./file-stat');
const fileName='package.json';
debug('fileName: '+fileName);
fileStat.getMTimeAsync(fileName);
fileStat.getMTimeSync(fileName);
debug('done.');

21
file-stat/package.json Normal file
View File

@ -0,0 +1,21 @@
{
"private": true,
"name": "file-last-modified",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Stefan Begerad",
"license": "GPL-3.0",
"devDependencies": {
"nodemon": "^2.0.7"
},
"dependencies": {
"fs": "0.0.1-security",
"http": "0.0.1-security",
"request": "^2.88.2"
}
}