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

dpape-node-service

v1.0.7

Published

Nodejs for server-side development integration

Downloads

2

Readme

dpape-node-service

Nodejs for server-side development integration

Install

npm install dpape-node-service -S
# OR
yarn add dpape-node-service -S

Initial Configuration

import { init } from "dpape-node-service";
import { join } from "path";
init({
  // mysql config items
  mysql: {
    user: "root",
    password: "**********",
    database: "databaseName",
  },
  // mysql mapper xml path
  mapperBasePath: join(__dirname, "./mapper"),
  // Save log address
  logs: join(__dirname, "./logs"),
  // mongodb config items
  mongodb: {
    user: "mongo",
    password: "*********",
    database: "databaseName",
    authDatabase: "admin",
  },
});

Quick Start

// index.js
import service, { app } from "dpape-node-service";
import { join } from "path";

const userApi = app();
// Last access path `/api/user/info`
userApi.get("/info", (req, res) => {
  res.send({
    statusCode: 200,
    data: {
      name: "admin",
      age: 25,
    },
  });
});
const apis = [
  {
    path: "/user",
    app: userApi,
  },
];
service({
  staticConfig: {
    url: "/",
    address: join(__dirname, "./static"),
  },
  apiPrefix: "/api",
  apis: apis,
  port: 8080,
});

Run the script

- node index.js
- Service app listening at http://localhost:8080

Use MySql database

Create the XML mapping file./mapper/xxx.xml

<?xml version="1.0" encoding="UTF-8"?>
<mapper>
  <item key="product_name" as="productName"></item>
  <item key="product_intro" as="productIntro"></item>
  <item key="id" as="productId"></item>
  <sql type="select" name="getProductInfo">
    select product_name,product_intro from product where id = #{id}
  </sql>
</mapper>

Invoke the defined method. The name attribute in.xml

import { sqlMapper } from "dpape-node-service";
async () => {
  try {
    const result = await sqlMapper("xxx.xml", "getProductInfo");
    return result;
  } catch (err) {
    return Promise.reject(err);
  }
};

Read on for more practical tips nodejs-mysql-mapper

Use MongoDB database

import { mongo } from "dpape-node-service";
//Query
async () => {
  try {
    const result = await mongo.querys("collectionName");
    return result;
  } catch (err) {
    return Promise.reject(err);
  }
};

//Insert
async () => {
  try {
    const result = await mongo.inserts("collectionName", {
      name: "test name",
      id: 1,
    });
    return result;
  } catch (err) {
    return Promise.reject(err);
  }
};

//Update
async () => {
  try {
    const result = await mongo.updates(
      "collectionName",
      { id: 1 },
      {
        name: "update - test name",
      }
    );
    return result;
  } catch (err) {
    return Promise.reject(err);
  }
};

Logs record

import { log } from "dpape-node-service";

// info logs
log.info("This is an info log");
// error logs
log.info("This is an error log");

Logs Output (in info.log and error.log):

# error.log
[2021-05-26T15:31:41.276] [ERROR] error - This is an error log
# info.log
[2021-05-26T15:31:41.274] [INFO] info - This is an info log

init Api

| Name | Describe | Default Value | Required | | :------------: | :------------------------: | :-----------: | :------: | | mysql | MySQL config info | -- | false | | mapperBasePath | mysql mapper xml path | -- | false | | mongodb | mysql mongodb config items | -- | false | | logs | Save log address | -- | false |

Start service Api

| Name | Describe | Default Value | Required | | :----------: | :---------------------------------------------------------------: | :-----------: | :------: | | port | Service port | -- | true | | apis | Web Service List for express app | -- | false | | apiPrefix | api prefix config | /api | false | | cross | Support cross-domain | false | false | | staticConfig | Static resource address. Supports one or more configuration items | -- | false | | headers | Custom request header information | -- | false |

Frequently Asked Questions

Q: Connect MySQL Error

ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server;

A: Please execute the following command in MySQL

ALTER USER '[username]'@'[ip]' IDENTIFIED WITH mysql_native_password BY '[password]';