A professional Node.js module that captures and tracks deployment information directly from Git logs. Extract commit details, deployment history, author information, version numbers, and build metadata in a structured, production-ready format.
- Git-Based Tracking: All deployment data sourced directly from Git logs (no external files needed)
- Server Start Time Tracking: Captures deployment time when server starts
- Complete Commit History: Track total commit count and access latest commit details
- Author Information: Capture author name, email, and committer details for auditing
- Version Management: Read version from
package.jsonautomatically - Professional Output: Beautiful formatted console output with box drawing
- Structured Data: Access deployment info via object notation for API integration
- CamelCase Convention: Consistent naming across all properties for better readability
- No Dependencies: Uses only Node.js built-in modules
npm install deploy-infoconst deployInfo = require('deploy-info');
// Display formatted deployment info
console.log(deployInfo.toString());
// Get complete data object
const info = deployInfo.getInfo();
console.log(info);
// Access specific properties (camelCase)
console.log(deployInfo.deployTime); // Server start time (ISO format)
console.log(deployInfo.commitCount); // Total commits in repository
console.log(deployInfo.version); // From package.json
console.log(deployInfo.authorName); // Current commit author
console.log(deployInfo.lastCommitHash); // Last commit hashdeployInfo.deployTime // Server start time (ISO format)
deployInfo.version // Version from package.json
deployInfo.commitCount // Total commits in repository (number)deployInfo.commitHash // Short commit hash
deployInfo.branchName // Current branch name
deployInfo.authorName // Commit author name
deployInfo.authorEmail // Commit author email
deployInfo.committerName // Commit committer namedeployInfo.lastCommitHash // Last commit hash (full)
deployInfo.lastCommitDate // Last commit timestamp (ISO)
deployInfo.lastCommitMessage // Last commit messagedeployInfo.latestTag // Latest git tagReturns comprehensive deployment information in structured format:
const info = deployInfo.getInfo();
console.log(JSON.stringify(info, null, 2));Response Structure:
{
version: "1.0.0",
deployTime: "2025-12-15T10:30:45.123Z",
deployCount: 42,
git: {
commit: {
hash: "a1b2c3d",
branch: "main",
date: "2025-12-15T10:30:00.000Z",
message: "Latest commit message",
author: {
name: "John Doe",
email: "john@example.com"
},
committer: "John Doe"
},
latestTag: "v1.0.0"
}
}Returns beautifully formatted string output for console display:
console.log(deployInfo.toString());Example Output:
╔════════════════════ DEPLOY INFO ══════════════════════╗
║ Version : 1.0.0
║ Deploy Count : 42
╠═════════════════════ LAST COMMIT ═════════════════════╣
║ Hash : a1b2c3d
║ Branch : main
║ Author : John Doe <john@example.com>
║ Date : 2025-12-15T10:30:00.000Z
║ Message : Latest commit message
╠═══════════════════════════════════════════════════════╣
║ Latest Tag : v1.0.0
╚═══════════════════════════════════════════════════════╝
The module tracks all commits in your repository and captures server start time:
- Deploy Time: Captured when the module is first loaded (server start time)
- Commit Count: Total number of commits in the repository (
git rev-list --count HEAD) - Last Commit: Always refers to the most recent commit (HEAD)
- No Special Format Required: Works with any commit message
All commits are tracked - no special commit message format required.
const express = require('express');
const deployInfo = require('deploy-info');
const app = express();
// Info endpoint
app.get('/api/info', (req, res) => {
res.json({
success: true,
data: deployInfo.getInfo()
});
});
// Health check endpoint
app.get('/health', (req, res) => {
res.status(200).json({
version: deployInfo.version,
deployCount: deployInfo.commitCount,
deployTime: deployInfo.deployTime
});
});
// Version endpoint
app.get('/version', (req, res) => {
res.json({
version: deployInfo.version,
commit: deployInfo.commitHash,
branch: deployInfo.branchName
});
});
app.listen(3000, () => {
console.log('Server running on port 3000');
console.log(deployInfo.toString());
});const deployInfo = require('deploy-info');
console.log('═══════════════════════════════════════');
console.log('DEPLOYMENT REPORT');
console.log('═══════════════════════════════════════');
console.log(`App Version: ${deployInfo.version}`);
console.log(`Deploy Time: ${deployInfo.deployTime}`);
console.log(`Total Commits: ${deployInfo.commitCount}`);
console.log(`Current Branch: ${deployInfo.branchName}`);
console.log(`Current Author: ${deployInfo.authorName}`);
console.log(`Last Commit: ${deployInfo.lastCommitHash}`);
console.log(`Last Commit Time: ${deployInfo.lastCommitDate}`);
console.log(`Latest Tag: ${deployInfo.latestTag}`);
console.log('═══════════════════════════════════════');const deployInfo = require('deploy-info');
const deploymentLog = {
timestamp: new Date().toISOString(),
version: deployInfo.version,
deployTime: deployInfo.deployTime,
currentBranch: deployInfo.branchName,
currentAuthor: {
name: deployInfo.authorName,
email: deployInfo.authorEmail
},
commitCount: deployInfo.commitCount,
lastCommit: {
hash: deployInfo.lastCommitHash,
date: deployInfo.lastCommitDate,
message: deployInfo.lastCommitMessage
}
};
// Send to logging service
console.log('DEPLOYMENT_EVENT', JSON.stringify(deploymentLog, null, 2));
// Or store in database
// db.deploymentLogs.insert(deploymentLog);# Add to package.json
{
"scripts": {
"deploy-info": "node -e \"console.log(require('deploy-info').toString())\""
}
}
# Run it
npm run deploy-info- Node.js: v12.0.0 or higher
- Git: Must be installed and available in system PATH
- package.json: Required in project root (for version reading)
Problem: Module cannot access Git information
Solution: Verify Git is installed and working
git status
git log --onelineProblem: No commits found in repository
Solution: Verify you have commits in your repository
git log --oneline
# Should show your commitsProblem: Cannot read version from package.json
Solution: Verify package.json exists and has version field
cat package.json | grep versionProblem: Git user not configured
Solution: Configure Git user
git config user.name "Your Name"
git config user.email "your.email@example.com"
# Or for global config
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"- Module Load: 50-100ms (captures deploy time and initializes)
- Getters Access: <1ms (lazy-loaded Git queries)
- getInfo(): 100-300ms (multiple Git queries)
- toString(): 100-300ms (includes getInfo() call)
Times vary based on repository size and system performance
- Cache the instance:
const deployInfo = require('deploy-info') - Use
getInfo()for API responses - Use
toString()for console output - Use getters for single values (lazy-loaded)
- Track server start time via
deployTime - Integrate with CI/CD pipelines
- Include deployment info in error reports
- Don't create multiple instances
- Don't expect
deployTimeto change (it's set at server start) - Don't call
getInfo()repeatedly (cache if needed) - Don't rely on Git info without proper Git setup
MIT - Free to use in any project
Created with ❤️ by Muhammad Huzaifa