npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

greenrefactor-js

v0.5.0

Published

GreenRefactor JavaScript SDK (WS + HTTP fallback) — spans & session

Downloads

18

Readme

GreenRefactor JavaScript SDK

GreenRefactor JS, web ve Node.js uygulamalarınızın enerji tüketimini ve karbon ayak izini ölçmenizi sağlayan hafif bir SDK'dır. greenrefactor backend servisi ile WebSocket veya HTTP üzerinden haberleşir.

🚀 Özellikler

  • Universal: Node.js ve Tarayıcı (React, Vue, vb.) ortamlarında çalışır.
  • Gerçek Zamanlı: WebSocket bağlantısı ile anlık veri akışı.
  • Fallback: WebSocket başarısız olursa HTTP üzerinden çalışmaya devam eder.
  • Resource Tracking: CPU ve RAM kullanımını otomatik raporlar.
  • Kolay Entegrasyon: Decorator veya wrapper fonksiyonlar ile mevcut kodunuza kolayca eklenir.

📦 Kurulum

npm install greenrefactor-js

Not: Sunucuyu başlatmak için Docker gereklidir. Docker Desktop'ın kurulu ve çalışır durumda olduğundan emin olun.

Not: Node.js ortamında WebSocket kullanmak istiyorsanız ws paketini de yüklemeniz önerilir: npm install ws

🏁 Hızlı Başlangıç

1. Backend Servisini Başlatın

Öncelikle GreenRefactor sunucusunun çalıştığından emin olun:

# NPM üzerinden sunucuyu başlatın (Docker gerektirir)
npx greenrefactor server

2. SDK'yı Başlatın

Uygulamanızın giriş noktasında (entry point) SDK'yı yapılandırın:

import { init, CarbonClient } from "greenrefactor-js";

// SDK konfigürasyonu
init({
  host: "127.0.0.1", // Backend host
  httpPort: 8123,    // HTTP port
  wsPort: 8124       // WebSocket port
});

// Session başlatma
const session = new CarbonClient({ service: "my-app", version: "1.0.0" });
await session.start();

3. İşlemleri Ölçün (Span Kullanımı)

Belirli bir işin ne kadar enerji tükettiğini ölçmek için carbonSpan kullanın:

import { carbonSpan } from "greenrefactor-js";

// Bir fonksiyonu sarmalayarak ölçümleme
const heavyTask = carbonSpan("database.query", async () => {
  // CPU yoğun veya uzun süren işlemler...
  await db.query("SELECT * FROM huge_table");
  return "done";
});

await heavyTask();

🌐 React / Frontend Örneği

React uygulamanızda useEffect içinde session başlatabilirsiniz:

import { useEffect } from 'react';
import { init, CarbonClient, carbonSpan } from 'greenrefactor-js';

function App() {
  useEffect(() => {
    init({ host: 'localhost', httpPort: 8123, wsPort: 8124 });
    const session = new CarbonClient({ service: 'frontend-app' });
    session.start();

    return () => { session.end(); };
  }, []);

  const handleProcess = async () => {
    await carbonSpan('user-action', async () => {
      // İşlem mantığı
      await fetch('/api/process');
    })();
  };

  return <button onClick={handleProcess}>İşlemi Başlat</button>;
}

⚙️ Konfigürasyon

init fonksiyonu aşağıdaki parametreleri alır:

| Parametre | Tip | Varsayılan | Açıklama | |-----------|------|------------|----------| | host | string | 127.0.0.1 | GreenRefactor sunucu adresi | | httpPort | number | 8123 | HTTP API portu | | wsPort | number | 8124 | WebSocket portu | | secure | boolean | false | HTTPS/WSS kullanımı |

📄 Lisans

MIT License - RmkodTech