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

c-core

v1.4.9

Published

The core api

Downloads

88

Readme

C-CORE

Build the REST API with json metadata.

This is a quick back-end system. You need create more modules, more versions, more APIs.. with only one json metadata

Requirements

Start MongoDB

mongod --port 27017

I. Getting started with global module

1. Install C-CORE
npm install -g c-core
2. Initial application
c-core init
3. Updating application
c-core update
4. Configuration environment
cp .env.copy .env
5. Start application
c-core start

II. Getting started with include as a module

1. Init the project
npm init project-name

Open the file package.json and update tag "scripts"

"scripts": {
  "init": "cross-env START_WITH=init node index.js",
  "start": "cross-env START_WITH=start node index.js",
  "update": "cross-env START_WITH=update node index.js",
  "generate-doc": "cross-env START_WITH=apidoc node index.js",
  "clean-doc": "find . -type f -name '_doc.js' -delete",
  "apidoc": "npm run generate-doc && apidoc -i api/ -o doc/ && npm run clean-doc"
}

Add dependencies

npm install --save c-core
npm install --save-dev apidoc
npm install --save-dev cross-env
2. Create index.js file
const core = require('c-core');
const cmd = process.env.START_WITH ? process.env.START_WITH : 'start';
try {
  core(cmd);
} catch (e) {
  console.error(e);
}
3. Configuration environment
cp .env.copy .env
4. Start application as development
npm run start

Now go to homepage http://localhost:3000

III. Add connection to database

1. Connection the MongoDB

Create file: api/database/mongo.json

{
  "driver": "mongoose",
  "connection": "mongodb://{HOST}:{PORT}/{DATABASE}",
  "options": {
    "useNewUrlParser": true,
    "useUnifiedTopology": true,
    "serverSelectionTimeoutMS": 5000
  }
}

Add configuration to setting file: api/setting.json

"database": [
    {
      "MONGO_DB_HOST": "localhost",
      "MONGO_DB_PORT": "27017",
      "MONGO_DB_NAME": "eco",
      "MONGO_DB_USERNAME": "",
      "MONGO_DB_PASSWORD": ""
    }
  ],

2. Connection the MySQL or MariaDB

npm install --save mysql

Create file: api/database/mysql.json

{
  "driver": "mysql",
  "database": "[DATABASE]",
  "config": {
    "connectionLimit" : 10,
    "host"            : "[SERVER]",
    "user"            : "[USERNAME]",
    "password"        : "[PASSWORD]",
    "database"        : "[DATABASE]"
  }
}

Add configuration to setting file: api/setting.json

"database": [
    {
      "MYSQL_DB_PORT": "3306",
      "MYSQL_DB_SERVER": "localhost",
      "MYSQL_DB_DATABASE": "eco",
      "MYSQL_DB_USERNAME": "eco",
      "MYSQL_DB_PASSWORD": "eco"
    }
  ],

3. Connection the SQL Server

npm install --save mssql

Create file: api/database/mssql.json

{
  "driver": "mssql",
  "database": "[DATABASE]",
  "connection": "Server=[SERVER],[PORT];Database=[DATABASE];User Id=[USERNAME];Password=[PASSWORD];",
  "config": {
    "user": "[USERNAME]",
    "password": "[PASSWORD]",
    "server": "[SERVER]",
    "database": "[DATABASE]",
    "connectionTimeout": 15000,
    "requestTimeout": 150000,
    "pool": {
      "min": 1,
      "max": 20,
      "idleTimeoutMillis": 30000
    },
    "options": {
      "port": "[PORT]",
      "appName": "node-mssql",
      "encrypt": false,
      "useUTC": true
    }
  }
}

Add configuration to setting file: api/setting.json

"database": [
    {
      "MSSQL_DB_PORT": "1433",
      "MSSQL_DB_SERVER": "10.0.0.15\\sql2012",
      "MSSQL_DB_DATABASE": "eco",
      "MSSQL_DB_USERNAME": "sa",
      "MSSQL_DB_PASSWORD": "2008"
    }
  ],

IV. How to test application

1. Output

HTTP/1.1 200 OK

[
  {
    "gender": "male",
    "_id": "5e7115bd926d13129e9b1cdf",
    "username": "username",
    "email": "[email protected]",
    "password": "password",
    "age": 65,
    "phone": "0999999999",
    "birthday": "2020-03-17T07:06:16.664Z",
    "salary": 1500.8,
    "avatar": "https://i.pinimg.com/originals/90/b0/b3/90b0b3b15ccecf9efda592b0bdf462aa.jpg",
    "last_ip": "30.230.33.25"
  }
]

Also when doing requests, it's good to know that:

  • If you make POST, PUT, PATCH or DELETE requests, changes will be automatically.
  • Your request body JSON should be object enclosed, just like the GET output. (for example {"name": "Foobar"})
  • Id values are not mutable. Any id value in the body of your PUT or PATCH request will be ignored. Only a value set in a POST request will be respected, but only if not already taken.
  • A POST, PUT or PATCH request should include a Content-Type: application/json header to use the JSON in the request body. Otherwise it will result in a 200 OK but without changes being made to the data.

2. Routes

    GET     -> /*/auth/get-token (*)
    GET     -> /*/auth/refresh-token (token)
    GET     -> /*/system/get-captcha (token)
    GET     -> /v1.0.0/setting/default (token)
    GET     -> /v1.0.0/setting/init/:password (token)
    GET     -> /v1.0.0/setting/get-by-id/:id (token,admin)
    PUT     -> /v1.0.0/setting/get-all (token,admin)
    POST    -> /v1.0.0/setting/add (token,admin)
    POST    -> /v1.0.0/setting/edit (token,admin)
    DELETE  -> /v1.0.0/setting/delete (token,admin)
    DELETE  -> /v1.0.0/setting/deletes (token,admin)
    POST    -> /v1.0.0/upload/file (token)
    PUT     -> /v1.0.0/user/login (token)
    PUT     -> /v1.0.0/user/logout (token)
    PUT     -> /v1.0.0/user/login-social (token)
    PUT     -> /v1.0.0/user/admin (token)
    PUT     -> /v1.0.0/user/check-username (token)
    PUT     -> /v1.0.0/user/check-email (token)
    PUT     -> /v1.0.0/user/forgot-password (token)
    PUT     -> /v1.0.0/user/reset-password (token)
    PUT     -> /v1.0.0/user/register-user (token)
    PUT     -> /v1.0.0/user/change-password (token,login)
    PUT     -> /v1.0.0/user/send-password (token,admin)
    POST    -> /v1.0.0/user/add-child (token,login)
    GET     -> /v1.0.0/user/get-children (token,login)
    DELETE  -> /v1.0.0/user/del-child (token,login)
    POST    -> /v1.0.0/user/add-user (token,admin)
    POST    -> /v1.0.0/user/edit-user (token,login)
    GET     -> /v1.0.0/user/get-by-id/:id (token,login)
    GET     -> /v1.0.0/user/get-all (token,admin)
    PUT     -> /v1.0.0/user/active-user (token,admin)
    PUT     -> /v1.0.0/user/disable (token,login)
    DELETE  -> /v1.0.0/user/delete-user (token,admin)
    DELETE  -> /v1.0.0/user/delete-users (token,admin)

V. CLI usage

1. c-core init
2. c-core update
3. c-core apidoc
4. c-core start [options]

Options:
  --port, -p     Start app with port
  --host, -h     Start app with host
  --help         Show help                  [boolean]
  --version, -v  Show version number        [boolean]

Examples:
  c-core init
  c-core update
  c-core apidoc
  c-core start -h localhost -p 3000

https://www.npmjs.com/package/c-core

VI. Deployment

1. Install software to serve

npm install -g pm2
pm2 startup

2. Copy and edit the environment in the process.json

cp process.json.copy process.json
pm2 start process.json
pm2 save

VII. Build to binary

npm install -g pkg
npm run pack-linux | pack-mac | pack-win

License

MIT