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

iwak-framework

v1.0.11

Published

A node micro-framework based on express.js [UNRELEASED]

Downloads

2

Readme

iwak-framework

A node micro-framework based on express.js

Requirements

  • NPM version 3 (Recommended to use Nodejs v6 LTS)

Installation

Since this framework is published to npm, you can install this with the following command:

$ npm install --save iwak-framework

Getting Started

Because this is core of framework, you should follow this configuration tutorial to make your project running.

First of all, you need to make a project structure like this:

.
├── app
│   ├── controllers
│   │   └── // your controller files lay down here
│   ├── libraries
│   ├── middleware
│   │   └── // your middleware files lay down here
│   ├── models
│   │   ├── // your data model files
│   ├── routes.js <-- this is file where you can define HTTP routes
│   └── views
│       └──  // your html files
├── config
│   ├── app.js 
│   ├── database.js
│   └── http.js
├── knexfile.js
├── npm_modules // you should learn node js first if you don't know this
├── migrations
│   └── // your migration files
├── package.json // you should learn node js first if you don't know this
├── public <-- directory for public and static files
├── server.js <-- main file
└── .env

Now, let check config/app.js file, it must contain an express configuration, i.e setting Access-Control-Allow-Origin. As expected, it only contains express middleware like this:

+ 'use strict';
+
+ module.exports = function (app) {
+  app.use(function(req, res, next) {
+    res.header("Access-Control-Allow-Origin", "*");
+    res.header("Access-Control-Allow-Headers", "X-Requested-With");
+    next();
+  });
+ };

Then, we'll focus on the file config/database.js. This file will be loaded by iwak-framework with bookshelf object, so you must write it as follows:

+ 'use strict';
+ module.exports = function (bookshelf) {
+
+ };

And, since it will retrieve bookshelf object, you can add plugins to it:

+ 'use strict';
+ module.exports = function (bookshelf) {
+   bookshelf.plugin('visibility');
+   bookshelf.plugin('pagination');
+ };

Now, for the file config/http.js. It contain a http server and will be loaded by iwak-framework with express object:

+ 'use strict';
+ const http   = require('http');
+ 
+ module.exports = function (app) {
+   const server = http.Server(app);
+ 
+   server.listen(env('APP_PORT', 3000), function () {
+     console.info('Listening on post 3000');
+   });
+ };

Ok, then in the file server.js where located in project root, we'll put this code to make the app running:

+ 'use strict';
+
+ const app = require('iwak-framework');
+
+ require('./app/routes');
+ require('./config/http')(app);
+ require('./config/boot');

Wait, what is app/routes?

Sorry, I didn't forget, but now I will explain to you what is it.

app/routes.js will contain the http route code. For example, you can write:

+ 'use strict';
+
+ const Route = use('Route');
+
+ Route.group({namespace: 'api', prefix: '/api'}, (Route) => {
+
+   Route.get('/', 'ExampleController.index');
+
+ }).error('json');

Then make another directory inside the controller with name api and create ExampleController.js inside it.

In the ExampleController.js write as follows:

+ 'use strict';
+
+ const Validator = use('Validator');
+ const Response  = use('Response');

+ class UserController {
+   constructor() {
+  }
+
+  index(req, res, next) {
+    let data = {
+       status: true,
+       data: {
+         foo: "bar"
+      }
+    }
+
+    return Response.success(res, data);
+   }
+ }

Finally, set the environment variable in the .env file:

+ NODE_ENV=development
+ 
+ APP_NAME=
+ APP_PORT=3000
+ APP_HOST=127.0.0.1
+ APP_DEBUG=true
+ APP_KEY=
+ 
+ DB_CLIENT=postgresql
+ DB_HOST=127.0.0.1
+ DB_PORT=
+ DB_DATABASE=
+ DB_USERNAME=
+ DB_PASSWORD=
+ DB_MIN_CONNECTION=1
+ DB_MAX_CONNECTION=1
+ 
+ TOKEN_SECRET=secret

Running server

$ node server.js

Done! Now you can access it via http://localhost:3000/api/example, it should return the following json:

{
  "status": true,
  "data": {
    "foo": "bar"
  }
}