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 🙏

© 2024 – Pkg Stats / Ryan Hefner

report-developer-server

v1.0.7

Published

This is report developer's server side package

Downloads

23

Readme

Report Developer Server

Report Developer Server is a report developer's server side package that facilitates database operations for report development and management.

Features

  • Database Connection: Establish a connection to a database by providing credentials.
  • Save Reports: Save new report in the connected database.
  • Retrieve Reports: Retrieve all saved reports from the connected database.
  • Report Development: Execute custom queries for report development purposes.

Installation

To install the package, use npm:

npm i report-developer-server

Usage

import Express from "express";
import dotenv from "dotenv";

// import all 4 methods provided by the report-developer-server
import {
  connect,
  reportDeveloper,
  saveReport,
  getReports,
} from "report-developer-server";

const app = Express();
app.use(Express.json());
dotenv.config();

// create dbCredentials a object of database credentials with host, port, user, password, and database feilds
// all the feilds of dbCredentials are required
const dbCredentials = {
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
};

// use try/catch inorder to catch the error and handle it
try {
  // 1) CONNECT : establishes connection with your database and creates a new ReportBuilder table if it doesn't exist inorder to save your reports
  // parameters: 1) dbCredentials [object] - used to create connection to your database
  //             2) logs [boolean] - pass 'true' if you want success and error logs (recommended during development)
  //                               - by default the value is 'false' so don't pass anything if you don't want the logs (recommended during production)
  connect(dbCredentials, true);
} catch (error) {
  // log the error in case when an error occurs
  console.error(error);
}

// create a POST route to handle POST requests to '/reportDeveloper'
// this endpoint is responsible to take the 'query' from the client, build the report by passing the 'query' to 'reportDeveloper()' and return a response with the obtained data from 'reportDeveloper()' to the client
app.post("/reportDeveloper", async (req, res) => {
  // destructure 'query' from the request body
  const { query } = req.body;

  // check if the 'query' parameter is missing
  if (!query) {
    // return a 400 Bad Request response if 'query' is not provided
    return res.status(400).json({ error: "Query parameter is missing" });
  }

  try {
    // 2) REPORT DEVELOPER: executes the 'query' on your database and returns the data
    // parameters: 1) query [String] - sqlQuery to be executed on your database to create your desired report
    const response = await reportDeveloper(query);

    // return a 200 OK response with the obtained data from 'reportDeveloper()'
    return res
      .status(200)
      .json({ data: response.data, error: null, status: response.status });
  } catch (error) {
    // if an error occurs during 'reportDeveloper()' execution, handle it here
    // return a 500 Internal Server Error response with the error message
    return res.status(500).json({ error: error.message });
  }
});

// create a POST route to handle POST requests to '/saveReport'
// this endpoint is responsible to take 'name' and 'query' from the client, pass them to 'saveReport()' which then saves the report in the 'reportBuilder' table on your database and return a success or error response to the client
app.post("/saveReport", async (req, res) => {
  // destructure 'name' and 'query' from the request body
  const { name, query } = req.body;

  // check if the 'name' or 'query' parameters are missing
  if (!name || !query) {
    // return a 400 Bad Request response with an error message if parameters are missing
    return res.status(400).json({ error: "Report parameters are missing" });
  }

  try {
    // 3) SAVE REPORT: saves your report in the 'reportBuilder' table on your database
    // parameters: 1) name [String] - name of your report
    //             2) query [String] - sqlQuery of your report
    const response = await saveReport({ name, query });

    // return a successful 200 OK response with the saved report data
    return res
      .status(200)
      .json({ data: response.data, error: null, status: response.status });
  } catch (error) {
    // handle any errors that occurred during the attempt to save the report
    // return a 500 Internal Server Error response with the error message
    return res.status(500).json({ error: error.message });
  }
});

// create a GET route to handle GET requests to '/savedReports'
// this endpoint is responsible to fetch all the saved reports from the 'reportBuilder' table on your database and return a response with the obtained reports to the client
app.get("/savedReports", async (req, res) => {
  try {
    // 4) SAVED REPORTS: fetches all the saved reports from 'reportDeveloper' table on your database and return a response with the obtained reports
    const response = await getReports();

    // return a successful 200 OK response with the obtained reports
    return res
      .status(200)
      .json({ data: response.data, error: null, status: response.status });
  } catch (error) {
    // handle any errors that occurred during the attempt to retrieve reports
    // return a 500 Internal Server Error response with the error message
    return res.status(500).json({ error: error.message });
  }
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, function () {
  console.log(`Server running on port ${PORT} `);
});