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

server-private

v1.6.3

Published

This a proyect of CD, we hope that enjoy of server.

Downloads

14

Readme

  • Fast mode development and build for production!
  • Make in typescript! :D
  • Use ejs templates for pages and components!

Table of Contents

How get?

Run:

  npm install server-private

Server-private cli

Use server-private cli.

$ server-private help
Usage: server-private [options] [command]

Options:
  -v, --version    output the version number
  -d, --discord    This command is for discord users, active 'Rich presence' (default: false)
  -h, --help       display help for command

Commands:
  dev [options]    Starting your proyect in mode development
  build            Starting build of your project for production
  start [options]  Start your application for production
  help [command]   display help for command

Concepts basics

There is a concepts basics for use server-private

Structure your directorys

Server private use a structure for your pages, styles, javascripts

Use a structure similar to this

📦src
 ┣ 📂components
 ┃ ┗ 📜header.ejs
 ┣ 📂css
 ┃ ┣ 📜styles.css
 ┣ 📂[Directory of your templates]
 ┃ ┗ 📜post.ejs
 ┣ 📂js
 ┃ ┣ 📜index.js
 ┣ 📂pages
 ┃ ┣ 📂dashboard
 ┃ ┃ ┗ 📜settings.ejs
 ┃ ┣ 📜index.ejs

Routes

Server-private has a file-system based router built on the concept of pages.

When added a file .ejs in the carpet pages, automatically available as a route.

The router will automatically routes files named index to the root of the directory pages.

  • pages/index.ejs/
  • pages/blog/index.ejs/blog

These routes are generated when you create a subfolder within a folder, this in the directory pages.

  • pages/user/profile.ejs--> /user/profile
  • pages/posts/html.ejs--> /posts/html

Config Files

File config.data.js

This is a file where you can add variables to your ejs files.

Create a file named config.data.js

Accept module/exports Ecmascript 6+ and CommonJS

Squemas:

  exports.[page] = {
    [variable: string]: // Function, string, object, any
  }
  export const [page] = {
    [variable: string]: // Function, string, object, any
  }

Examples

// This variable is available on the index page
export const index = {
  mode: "development",
};
// With commonJs
exports.index = {
  mode: "development",
};

File create.pages.js

This is a file where you can create pages programmatically

Create a file named create.pages.js

Accept module/exports Ecmascript 6+ and CommonJS

Examples

// With plugins and module/exports Ecmascript 6+
import Plugins from "server-private/@plugins";

export default function createPage({ action, listenTemplate }) {
  // This is plugins of server-private
  const { json } = new Plugins().setFilesJson("./src/posts");
  // This for the server watch this directory
  listenTemplate("./src/templates");
  // This is implemantion
  json.forEach(({ data, name }) => {
    action({
      data,
      path: name,
      template: "./src/templates/post.ejs",
    });
  });
}
// With Custom data and commonJS
// If you want use plugins
// const { default: Plugins } = require('server-private/@plugins');

modules.exports = function createPage({ action, listenTemplate }) {
  const pages = [
    {
      name: "First-page",
      data: {
        mode: "development",
        title: "My first page programmatically",
      },
    },
  ];
  // This for the server watch this directory
  listenTemplate("./src/templates");
  // This is implemantion
  pages.forEach(({ data, name }) => {
    action({
      data,
      path: name,
      template: "./src/templates/post.ejs",
    });
  });
};

API

Plugins

This is a class where you can initialize the plugins, like json

Parameters

  • param Object is a configuration object (optional, default {promise:false,test:false})
    • param.promise boolean this attribute converte all methods to promise (optional, default false)

setFilesJson

This method is for set path of your files json

Parameters

  • params (string | {dist: string, id: string}) This is the relative path where are your files json (optional, default ./src/jsons)
  • id string? This id save a instance json

Examples

// returns a array of your data
// In create.pages.js
const functionCreatePage = () => {
const jsons = new Plugins().setFilesJson('./src/jsons', 'id').getJson();
// or
const jsons = new Plugins().setFilesJson({
 dist: './src/jsons',
 id: 'id',
}).getJson();
}
export default functionCreatePage;

Returns {getJson} where is getJson, this method is where you get your data

setFilesJsonPromise

This method is for set path of your files json

Parameters

  • params (string | {dist: string}) This is the relative path where are your files json (optional, default ./src/jsons)

Examples

// returns a array of your data
// In create.pages.js
const functionCreatePage = async () => {
const { getJsonPromise } = await new Plugins().setFilesJson('./src/jsons', 'id');
// or
const { getJsonPromise } = await  new Plugins().setFilesJson({
 dist: './src/jsons',
 id: 'id',
});
}
export default functionCreatePage;

Returns Promise<{getJsonPromise}> is a promise that return in then the objet with the method getJsonPromise(this is for get your data in a promise)

getJson

This method return all data of your json files

Examples

// In create.pages.js
const functionCreatePage = () => {
new Plugins().setFilesJson('./src/jsons');
// returns all data
 const dataJson = new Plugins().getJson('id');
};
export default functionCreatePage;

getJsonPromise

This method return all data of your json files

Examples

// In create.pages.js
const functionCreatePage = async () => {
await new Plugins().setFilesJsonPromise('./src/jsons', 'id');
// returns all data
 const dataJson = await new Plugins().getJsonPromise('id');
};
export default functionCreatePage;

Returns Promise<{id: string, dir: string, data: Array<{name: String, pathRelative: String, data: Object}>}> is a promise that return all your data of json files

isPromise

This method return if your methods are promises

Examples

const { isPromise } = new Plugins();
console.log(isPromise());
// Output: false

Returns boolean A boolean if your methods Plugins are promises