diff --git a/file-stat/.gitignore b/file-stat/.gitignore new file mode 100644 index 0000000..81a38be --- /dev/null +++ b/file-stat/.gitignore @@ -0,0 +1 @@ +.env* diff --git a/file-stat/README.md b/file-stat/README.md new file mode 100644 index 0000000..3313043 --- /dev/null +++ b/file-stat/README.md @@ -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 +``` diff --git a/file-stat/README.md.license b/file-stat/README.md.license new file mode 100644 index 0000000..2e76dc1 --- /dev/null +++ b/file-stat/README.md.license @@ -0,0 +1,5 @@ +/* + * SPDX-FileCopyrightText: 2022 Stefan Begerad + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ diff --git a/file-stat/file-stat.js b/file-stat/file-stat.js new file mode 100644 index 0000000..100305f --- /dev/null +++ b/file-stat/file-stat.js @@ -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 +}; diff --git a/file-stat/index.js b/file-stat/index.js new file mode 100644 index 0000000..435d32c --- /dev/null +++ b/file-stat/index.js @@ -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.'); diff --git a/file-stat/package.json b/file-stat/package.json new file mode 100644 index 0000000..4db97ed --- /dev/null +++ b/file-stat/package.json @@ -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" + } +}