The Wayback Machine - https://web.archive.org/web/20241002172819/https://www.geeksforgeeks.org/node-js-stats-birthtime-property/
Open In App

Node.js stats.birthtime Property

Last Updated : 08 Oct, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The stats.birthtime property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is created.

Syntax:

stats.birthtime

Return Value: It returns a Date that represents the timestamp when the file has been created.

Below examples illustrate the use of stats.birthtime property in Node.js:

Example 1:




// Node.js program to demonstrate the   
// stats.birthtime property
  
// Accessing fs module
const fs = require('fs');
  
// Calling stats.birthtime property
// from  fs.Stats class using stat
fs.stat('./', (err, stats) => {
    if (err) throw err;
  
    // The timestamp when the file is created
    console.log("Using stat: " + stats.birthtime);
});
  
// Using lstat
fs.lstat('./filename.txt', (err, stats) => {
    if (err) throw err;
  
    // The timestamp when the file is created
    console.log("Using lstat: " + stats.birthtime);
});


Output:

Using stat: Wed May 13 2020 18:38:31 GMT+0530 (India Standard Time)
Using lstat: Sun Jun 21 2020 01:22:55 GMT+0530 (India Standard Time)

Example 2:




// Node.js program to demonstrate the   
// stats.birthtime property
  
// Accessing fs module
const fs = require('fs').promises;
  
// Calling fs.Stats stats.birthtime
(async () => {
    const stats = await fs.stat('./example_file.txt');
  
    // The timestamp when the file is created 
    console.log("Using stat synchronous: "
        + stats.birthtime);
})().catch(console.error)


Output:

Using stat synchronous: Sun Jun 21 2020 01:22:55 GMT+0530 
                                    (India Standard Time)

Note: The above program will compile and run by using the node filename.js command and use the file_path correctly.

Reference: https://nodejs.org/api/fs.html#fs_stats_birthtime



Previous Article
Next Article

Similar Reads

Node.js stats.atimeMs Property from fs.Stats Class
The stats.atimeMs property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is accessed last time since the POSIX epoch expressed in milliseconds. Syntax: stats.atimeMs; Parameters: This property does not use any parameters. Return Value: It returns a number or BigInt value that repres
2 min read
Node.js stats.mtimeMs Property from fs.Stats Class
The stats.mtimeMs property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is modified last time since the POSIX epoch expressed in milliseconds. Syntax: stats.mtimeMs; Parameters: This property does not accept any parameters. Return Value: It returns a number or BigInt value that rep
2 min read
Node.js stats.mode Property from fs.Stats Class
The stats.mode property is an inbuilt application programming interface of the fs.Stats class which is used to get the file type and mode as bit-field. Syntax: stats.mode; Return Value: It returns a number or BigInt value that represents a bit-field that describes the file type and mode. Below examples illustrate the use of stats.mode in Node.js: E
2 min read
Node.js stats.nlink Property from fs.Stats Class
The stats.nlink property is an inbuilt application programming interface of the fs.Stats class which is used to get the number of hard-links for the file. Syntax: stats.nlink; Return Value: It returns a number or BigInt value which represents the number of hard-links for the file. Below examples illustrate the use of stats.nlink property in Node.js
2 min read
Node.js stats.uid Property from fs.Stats Class
The stats.uid property is an inbuilt application programming interface of the fs.Stats class is used to get the numeric (number / bigint) identity of the user to which the file belongs to. Syntax: stats.uid; Return Value: It returns a number or BigInt value which represents the identity of the user that owns the file. Below examples illustrate the
2 min read
Node.js stats.gid Property from fs.Stats Class
The stats.gid property is an inbuilt application programming interface of the fs.Stats class which is used to get the numeric (number / bigint) identity of the group to which the file belongs to. Syntax: stats.gid; Return Value: It returns a number or BigInt value which represents the identity of the group that owns the file. Below examples illustr
2 min read
Node.js stats.rdev Property from fs.Stats Class
The stats.rdev property is an inbuilt application programming interface of the fs.Stats class is used to get the numeric (number / bigint) identity of the device in which the file is stored in the file is considered to be "special". Syntax: stats.rdev; Return Value: It returns a number or BigInt value that represents the identity of the device in w
2 min read
Node.js stats.size Property from fs.Stats Class
The stats.size property is an inbuilt application programming interface of the fs.Stats class is used to get the size of the file in bytes. Syntax: stats.size; Return Value: It returns a number or BigInt value that represents the size of the file in bytes. Below examples illustrate the use of stats.size property in Node.js: Example 1: // Node.js pr
2 min read
Node.js stats.blksize Property from fs.Stats Class
The stats.blksize property is an inbuilt application programming interface of the fs.Stats class is used to get the block size for I/O operations in the file system in bytes. Syntax: stats.blksize; Return Value: It returns a number or BigInt value which represents the block size for I/O operations in the file system in bytes. Below examples illustr
2 min read
Node.js stats.blocks Property from fs.Stats Class
The stats.blocks property is an inbuilt application programming interface of the fs.Stats class is used to get the number of blocks allocated for the file. Syntax: stats.blocks; Return Value: It returns a number or BigInt value that represents the number of blocks allocated for the file. Below examples illustrate the use of stats.blocks property in
2 min read
Node.js stats.ctimeMs Property from fs.Stats Class
The stats.ctimeMs property is an inbuilt application programming interface of the fs.Stats class that is used to get the timestamp when the file status has been changed last time since the POSIX epoch expressed in milliseconds. Syntax: stats.ctimeMs; Return Value: It returns a number or BigInt value that represents the timestamp when the file statu
2 min read
Node.js stats.birthtimeMs Property from fs.Stats Class
The stats.birthtimeMs property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is created since the POSIX epoch expressed in milliseconds. Syntax: stats.birthtimeMs; Return Value: It returns a number or BigInt value that represents the timestamp when the file is created since the POSI
2 min read
Node.js stats.isDirectory() Method from fs.Stats Class
The stats.isDirectory() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object describes a file system directory or not. Syntax: stats.isDirectory(); Parameters: This method does not accept any parameters. Return: This method returns a boolean value, which is true if fs.Stats obje
2 min read
Node.js stats.isCharacterDevice() Method from fs.Stats Class
The stats.isCharacterDevice() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object is of a character device or not. Syntax: stats.isCharacterDevice(); Parameters: This method does not accept any parameter. Return Value: This method returns a boolean value, which is true if fs.St
1 min read
Node.js stats.isFile() Method from fs.Stats Class
The stats.isFile() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object describes a file or not. Syntax: stats.isFile(); Parameters: This method does not accept any parameters. Return Value: This method returns a boolean value, which is true if fs.Stats object describes a file,
2 min read
Node.js stats.isBlockDevice() Method from fs.Stats Class
The stats.isBlockDevice() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object is of a block device or not. Syntax: stats.isBlockDevice(); Parameters: This method does not accept any parameter. Return Value: This method returns a boolean value, i.e. true if fs.Stats object descr
1 min read
Node.js stats.ctime Property
The stats.ctime property is an inbuilt application programming interface of the fs.Stats class that is used to get the timestamp when the file status has been changed last time. Syntax: stats.ctime Return Value: It returns a date value that represents the timestamp when the file status has been changed last time. Below examples illustrate the use o
2 min read
Node.js stats.mtimeNs Property
The stats.mtimeNs property is an inbuilt application programming interface of the fs.Stats class used to get the timestamp when the file is modified last time since the POSIX epoch expressed in nanoseconds. Syntax: stats.mtimeNs; Parameters: Properties does not have any parameter, but during creation of stats object {bigint:true} must be passed as
2 min read
Node.js stats.ctimeNs Property
The stats.ctimeNs property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file status has been changed last time since the POSIX epoch expressed in nanoseconds. Syntax: stats.ctimeNs; Parameters: Properties does not have any parameter, but during creation of stats object {bigint:true} mus
2 min read
Node.js stats.atimeNs Property
The stats.atimeNs property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is accessed last time since the POSIX epoch expressed in nanoseconds. Syntax: stats.atimeNs; Parameters: This property does not have any parameter, but during creation of stats object {bigint:true} must be pass
2 min read
Node.js stats.birthtimeNs Property
The stats.birthtimeNs property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is created since the POSIX epoch expressed in milliseconds. Syntax: stats.birthtimeNs; Parameters: This property does not have any parameters, but during creation of stats object {bigint:true} must be passe
2 min read
Node.js stats.atime Property
The stats.atime property is an inbuilt application programming interface of the fs.Stats class used to get the time and date when the file is accessed last time. Syntax: stats.atime; Parameters: Properties does not have any parameter. Return Value: It returns a Date which represents the time and date when the file is accessed last time. Below examp
2 min read
Node.js stats.mtime Property
The stats.mtime property is an inbuilt application programming interface of the fs.Stats class is used to get the timestamp when the file is modified last time. Syntax: stats.mtime; Parameters: Properties does not have any parameter. Return Value: It returns a Date which represents the timestamp when the file is modified last time. Below examples i
2 min read
Node.js stats.ino Property
The stats.ino property is an inbuilt application programming interface of the fs.Stats class is used to get the "Inode" number of the file specified by the file system. Syntax: stats.ino; Parameters: This property does not have any parameter. Return Value: It returns a number or BigInt value which represents the "Inode" number of the file specified
2 min read
Node.js stats.dev Property
The stats.dev property is an inbuilt application programming interface of the fs.Stats class is used to get the numeric (number / bigint) identity of the device in which the file is situated. Syntax: stats.dev; Parameters: This property does not accept any parameter. Return Value: It returns a number or BigInt value which represents the identity of
2 min read
Node.js stats.isFIFO() Method
The stats.isFIFO() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object describes a first-in-first-out (FIFO) pipe or not. Syntax: stats.isFIFO(); Parameters: This method does not accept any parameter. Return Value: This method returns a boolean value, which is true if fs.Stats
2 min read
Node.js stats.isSymbolicLink() Method
The stats.isSymbolicLink() method is an inbuilt application programming interface of the fs.Stats class which is used to check whether fs.Stats object describes a symbolic link or not. Syntax: stats.isSymbolicLink(); Parameters: This method does not accept any parameter. Return: This method returns a boolean value, which is true if fs.Stats object
2 min read
Node.js Automatic restart Node.js server with nodemon
We generally type following command for starting NodeJs server: node server.js In this case, if we make any changes to the project then we will have to restart the server by killing it using CTRL+C and then typing the same command again. node server.js It is a very hectic task for the development process. Nodemon is a package for handling this rest
1 min read
Top 3 Best Packages Of Node.js that you should try being a Node.js Developer
Node.js is an open-source and server-side platform built on Google Chrome's JavaScript Engine (V8 Engine). Node.js has its own package manager called NPM( Node Package Manager) which has very useful and incredible libraries and frameworks that makes our life easier as a developer to work with Node.js. The 3 Best Packages of Node.js that you should
4 min read
Node.js Connect Mysql with Node app
Node.js is a powerful platform for building server-side applications, and MySQL is a widely used relational database. Connecting these two can enable developers to build robust, data-driven applications. In this article, we'll explore how to connect a Node.js application with a MySQL database, covering the necessary setup, configuration, and basic
2 min read