Giter Site home page Giter Site logo

light.js's Introduction

light.js is simplest micro framework, with minimal npm package

How you can use it ?

  1. Create empty project
  2. Clone this repo
  3. Run npm install path-to-regexp && node sample.js

path-to-regexp only 1 package is used in light.js

You can create new route with .setRoute(path, method, handler) or .get(path, handler) -> .post(), .put(), .patch(), .delete()}

You can get params from 'GET, POST, PUT, PATCH, DELETE' request like this:

 app.post('/product/:id/update', (req, res) => {
     // req.params is contain params

     let getRequestParams    = req.params.get;  // object,
     let postRequestParams   = req.params.post; // object
     let putRequestParams    = req.params.post; // object
     let patchRequestParams  = req.params.post; // object
     let deleteRequestParams = req.params.post; // object
     
 })

-- You can use custom res methods like 'send(data, {status: 200, contentType: 'text/html''})', 'json(object, {status: 200, contentType: 'application/json''})' or 'notFound(data)'

  1. .send()
    server.get('/', (req, res) => {
        return res.send('Hello, World !', {status: 200});
    })
  1. .json()
    server.get('/', (req, res) => {
        return res.json({'message': 'Hello, World !'}, {status: 200});
    })
  1. .notFound()
    server.get('/getProduct/:id', (req, res) => {
        ... You code here
        
        if(!item.exists())
           return res.notFound(`product with id: ${req.params.get.id} not found`, {status: 404});
    })

Default server port is 3000, but you can change it server.listen({port: 4000});

Files

'sample.js' - is example of light.js

'light.js' - is main file of light.js, in this file you can find routing system and ...

'extended-http' - is extended nodejs default package 'http' with several methods(.send(), .json(), ...)

TODO LIST

  • Server
  • Router register server.setRoute(), server.get() .post() .put() .patch() .delete()
  • Custom res.send(), res.json(), res.notFound() methods
  • Setup view engine(ejs, ...)
  • Create logger module

About

I made the project for informational purposes, you can take it and upgrade it, maybe this project will help you understand how the frameworks works.

light.js's People

Contributors

callmedavron avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.