1.0.1 • Published 4 years ago

eonil v1.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Eonil

contributions welcome Known Vulnerabilities

Eonil is a wrapper for Express and SocketIO to create a server in one line! (you can choose whether to use express alone or express+socketio)

Installation

This is done using the npm install command:

$ npm install eonil

Usage

Creating an express app with static files in one line

//If no port is set the server will start in port 5000 by default
const Eonil = require("eonil");
const app = new Eonil({ port: 5000, directory: "/public" }).StartServer().GetApp();

Creating an express app with no files in one line

const Eonil = require("./index");
const app = new Eonil({}).StartServer().GetApp();

app.get("/", (req, res) => {
	res.send("Hello");
});

Creating a socket.io-express app

const Eonil = require("eonil");
const SM = new Eonil({
	port: process.env.PORT,
	directory: "./public",
	isSocket: true,
});
const app = SM.StartServer().GetApp();
const io = SM.GetIo();

Retrieving all instances of the manager

const Eonil = require("eonil");
const SM = new Eonil({...});
//Only returns io instance if isSocket is true
const { app, express, io } = SM.GetAllInstances();

Examples

Express

const Eonil = require("eonil");
//If no port is set the server will start in port 5000 by default
const app = new Eonil({ directory: "/public" }).StartServer().GetApp();

app.get("/api/test", async (req, res) => {
	res.send("Hello there");
});

Socketio

const Eonil = require("eonil");
const SM = new Eonil({
	port: process.env.PORT,
	directory: "./public",
	isSocket: true,
});
const app = SM.StartServer().GetApp();
const io = SM.GetIo();

app.get("/api/test", async (req, res) => {
	res.send("Hello there");
});

io.on("connection", (socket) => console.log(socket));

Plans for the future

  • [] Add certificates support for https
  • [] Creating self signed certificates on the fly for https support

Built With

JavaScript

Contributors

Joel Castillo

License

This project is licensed under the MIT License - see the LICENSE.md file for details Acknowledgments