xtra-express

1.1.5 • Public • Published


Logo

Xtra-Express

A NPM Utility Package For Express

Created For The Documatic Hackathon


Repository»

Express · Report Bug · Documatic

Contributors Forks Stargazers Issues MIT License

About The Project

Express is a popular Node.js package useful for many simple tasks that require hosting files online such as a simple website or a api, and Xtra-Express is for the sole purpose of making this package even easier by simplifying tasks that would take hundreds of lines of code if done manually. It will save you time and effort, and will hopefully enhance your website, api or whatever you wish to build.

Prerequisites

NPM is required to run this project

If you do not already have npm you can install it from https://nodejs.org/en/download/

npm install -g npm

Installation

npm install -g xtra-express

Usage

const {express} = require('xtra-express')                               // Import xtra-express
const app = express();                                                  // create app

app.set('view engine','ejs')                                            // Set ejs to view engine
app.use(express.static('xtra-express'))                                 // This is necessary if you want the views chart page

express.init(['index-ejs'])                                             // Initializes all your files

                                                                        // Make sure to replace `.` with `-` in all 
                                                                        // file names you provide to the package
                                           
app.get('/', async (req, res) => {          
    express.viewsUpdate('index-ejs')                                    // Tells the package that a new view has occured
    res.render('index');                                                // Render your content inside the `views` folder as normal
 });

 app.get('/views', async (req,res) => {
    res.render('xtra-express/index-ejs')                                // Render the views chart for the specified file on that path
 })

 app.listen(5001);

Not all functions have been utilised in the simple demo above and futher functions can be seen in the section below

Functions

express.init(['file-name']) 

Initializes all files given in the array for view tracking and the views chart. Processes can also be done individually through the functions below.

express.viewsInit('file-name')

Initializes the view tracking and creates all necessary files

express.chartInit('file-name')

Initalizes the views chart and creates all necessary files. This will create a file at ./views/xtra-express/file-name.ejs, edit this file as per the needs of your site. The chart can be displayed on any route by using res.render('xtra-express/file-name').

To make sure no content gets cut out, only the last 30 days of recorded data will be shown in the chart

express.viewsUpdate('file-name')

Should be placed on the route where you would like to track views. It will be called on every visit, updating the view count each time.

⚠️ If you are using nodemon: Nodemon will restart your site on every visit due to the changing of a .json file. To avoid this place the following code in your package.json

 "nodemonConfig": {
  "ignore": ["xtra-express/*/*.json"]
 },
express.views('file-name')

Run at any time to get the current number of views printed in the console. This can also be stored in a variable where it will simply return the number of views

express.serverUptime()

Returns the server uptime in the format days:hours:minutes:seconds. Recommended to put this in either a console.log() or variable.

Demonstration

Above is a example of what a chart page would look like. It is an interactive file and the exact value of the date can be viewed by hovering over the point. The chart also acts effeciently by only displaying every second date on the bottom to ensure no text gets cut out, however if needed, the exact date can be seen by hovering over a point.

📊 This feature is made possible by the Google Charts Api

Contributing

Contributing will help keep this project alive and is greatly appreaciated. If you would like to contribute please follow the steps below.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.md for more information.

(back to top)

Documatic

Documatic is a search engine for your codebase; Ask documatic a question and find relevant code snippets and insights in seconds.

https://www.documatic.com/ Documatic acts as a search engine for your codebase; once you describe what you're looking for, Documatic pulls up related code or documentation making it easier to find what you're looking for in seconds!

Not sitting next to each other? No problem. Ask Documatic questions of your codebase to learn and understand your code in seconds. Documatic is the team member you wish you had

Our Visual studio Code extension: https://marketplace.visualstudio.com/items?itemName=Documatic.documatic

Package Sidebar

Install

npm i xtra-express

Weekly Downloads

1

Version

1.1.5

License

ISC

Unpacked Size

419 kB

Total Files

7

Last publish

Collaborators

  • dhyan-tanna