vite.js

1.0.1 • Public • Published

Vite.js

Build Status Actions Status NPM

Welcome

Vite.js is the simplest way for nodejs developers to bootstrap a web server and thus smoothen the process of project creation.
Vite.js has a documentation that is super easy to follow

Features

  • Built-in CLI
  • Optimized
  • Body parsing and Cooky paring
  • Built-in logging capabilities
  • Session
  • Helmet
  • Trust proxy
  • Plugin with a Mongo Database
  • Express connection
  • Production ready

Install

$ npm i -g --save vite.js

Basic Use

const ViteJS = require("vite.js");
const { app, database } = new ViteJS({ name: "test" });

Documentation

Startup

const ViteJS = require("vite.js");
new ViteJS({ name: "test" });

Options

Name

  • Kind: String
  • Description: Used for logging purposes
new ViteJS({ name: "test" });

Port

  • Kind: Integer (0-65536)
  • Description: Port to run web server on
  • Default: 8080
new ViteJS({ 
  name: "test",
  port: 8080
});

Log

  • Kind: Boolean
  • Description: If set to true, logs path of request, speed and status code sent to the console
new ViteJS({ 
  name: "test",
  port: 8080,
  log: true
});

Mongo

  • Kind: String
  • Description: MongoDB connection string
new ViteJS({ 
  name: "test",
  port: 8080,
  log: true,
  mongo: "mongodb://localhost:27017/"
});

Routes

  • Kind: Array
  • Description: Assigning routes to the application
new ViteJS({ 
  name: "test",
  port: 8080,
  log: true,
  routes: [
    {
     url:'/route1',
     router: require('./router1.js')
    },
    {
     url:'/route2',
     router: require('./router2.js')
    }
  ],
  mongo: "mongodb://localhost:27017/"
});

Views Directory

  • Kind: String
  • Description: Path to the views directory
new ViteJS({ 
  name: "test",
  port: 8080,
  log: true,
  viewsDir: "./views",
  mongo: "mongodb://localhost:27017/"
});

Public Directory

  • Kind: String
  • Description: Path to public directory for express for hosting static files
new ViteJS({ 
  name: "test",
  port: 8080,
  log: true,
  publicDir: "./public",
  mongo: "mongodb://localhost:27017/"
});

Express

Under the hood, Vite.js uses express with body parsing and cookie parsing capabilities to start a web server and control it. Additionally, it uses Helmet to keep the server secure and functional so that you can focus on the development and leave these to Vite.js .


There are primarily two methods to access the express server:
  • Method 1
const app = require("vite.js").app;
  • Method 2
const ViteJS = require("vite.js");
const { app } = new ViteJS({ name: "test" });

Example usage

const ViteJS = require("vite.js");
const { app } new ViteJS({ name: "test});
 
app.use(function(req, res, next) {
    req.session.name = "AlQaholic007";
    console.log("Sample use of middlewares with vite.js");
    next();
});
 
app.get("/", function(req, res) {
    res.status(200).send("This works!");
});
 
app.post("/body", function(req, res) {
    res.status(200).send(req.body);
});
 
app.get("/session", function(req, res) {
    res.status(200).send(req.session.name)
});

Database

Vite.js leverages enmap and enmap-mongo to connect to your mongo database in a fast and easy manner.


Accessing database also has two methods:
  • Method 1
const database = require("vite.js").database;
  • Method 2
const ViteJS = require("vite.js")
const { database } = new ViteJS({ name: "test" });

Example usage

const ViteJS = require("vite.js");
const { database } = new ViteJS({ name: "test" });
 
database.set("AlQaholic007", "Vite.js");
 
console.log("Welcome to " + database.get("AlQaholic007") + "!");

Advanced uses

EJS

const ViteJS = require("vite.js");
const { app, database } = new ViteJS({
  name: "ejs_setup",
  port: 8080,
  log: true,
  mongo: "mongodb://localhost:27017/",
  viewsDir: "./views",
  publicDir: "./public"
});
 
app.set("view engine", "ejs");
 
app.get("/", function(req, res) {
  res.render("index", { time: new Date() });
});

Sessions

const ViteJS = require("vite.js");
const { app, database } = new ViteJS({
  name: "session_setup",
  port: 8080,
  log: true,
  mongo: "mongodb://localhost:27017/",
  viewsDir: "./views",
  publicDir: "./public"
});
 
app.set("view engine", "ejs");
app.use(function(req, res, next) {
  req.session.username = "Tester";
  next();
});
 
app.get("/", function(req, res) {
  res.render("index", { name: req.session.username });
});

Authors

License

(The MIT License)

Copyright (c) 2020 AlQaholic007 mail@sohamp.dev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i vite.js

Weekly Downloads

15

Version

1.0.1

License

MIT

Unpacked Size

209 kB

Total Files

43

Last publish

Collaborators

  • alqaholic007