feat(file-stat): initial commit
This commit is contained in:
parent
7a64523e34
commit
f7de6852aa
|
@ -0,0 +1 @@
|
|||
.env*
|
|
@ -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
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Stefan Begerad <stefan@begerad.de>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
|
@ -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
|
||||
};
|
|
@ -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.');
|
|
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue