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

nucklejs

v1.3.0

Published

![nucklejs](https://i.ibb.co/x7s4QYJ/Nuckle-JS-Logo.jpg)

Downloads

6

Readme

nucklejs

NuckleJS is a node.js framework built on top of express.js. It's build for creating web applications just like you whould with express but with less code, files and effort. NuckleJS is fast, you can get a server up and running in just two lines of code

Installation

Use the package manager npm to install NuckleJS.

npm install nucklejs

Start a server

const { createServer } = require('nucklejs')
//The createApp method will also return the express app itself
const server = createServer(8080)

And that's it!

You now have a server running on port 8080. You may have noticed that it says "Production Mode" in the console. That's becouse NuckleJS comes pre-configured for .env files and is looking at the NODE_ENV variable

Configure .env

Here you'll see how to configure your .env file. First of all create a new file named ".env". Now, down below you'll see what variable to define to tell NuckleJS what environment you're working in.

You can also define your server port here by simply defining a PORT variable

NODE_ENV=development
PORT=8080

Routing

Routing in NuckleJS is a bit diffrent from express. BUT it's simple! The method createRouter() is used to define your router containing all of your routes. Let me show you

const { createRouter } = require('nucklejs')
const mainController = require('./controllers/main.js')

const router = createRouter([
    {
        path: '/',
        method: 'GET',
        controller: mainController.root
    }
])

module.exports = router

That's how easy it is to define your routes. I recommend you creating your router in router.js file for a good project structure. But now, how do we use our routes in our application...Simple, in the createServer() method you can pass in your router as the second argument

const server = createServer(8080, require('./router.js')

Simple as that!

Now NuckleJS will handle the rest your routes are now in use in your application

Route Guards

Now to route guards. What is it? It's a middleware you run before the actuall request controller / handler. Like a middle man. It's often used when handeling access to certain endpoins. Let me show you...

const { createRouter } = require('nucklejs')
const mainController = require('./controllers/main.js')
const { mainGuard } = require('./guards/main.js'=

const router = createRouter([
    {
        path: '/',
        method: 'GET',
        controller: mainController.root
    },
    {
        path: '/protected',
        method: 'POST',
        controller: maincontroller.protected,
        guard: mainGuard
    }
])

module.exports = router

It's that simple to create a protected route using NuckleJS. Now our middleware "mainGuard" will run before the actuall controller for the route does

Using other middlewares

You may want to use something like cors in your application. No problem, like i said the createServer() also return the actuall app itself. So you can simply do:

const cors = require('cors')
const server = createServer(8080, require('./router.js')

server.use(cors())

It's that simple to use any other middleware you like

Cookies

Sometimes you may want to use cookies in your application eighter set or read cookies. NuckleJS comes pre-loaded with cookie-parser and is therefore ready to set and read cookies. Example:

//This is an example of an controller for a route
module.exports.main = (req,res) => {
    res.cookie('My-Name', 'Rasmus Nitsche - NitscheDev')
    res.send('Yay, a cookies has been set')
}

And it's that easy. If you want to know more about cookies check out cookie-parser's documentation...

License

MIT