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

noda-fw

v1.0.9

Published

This framework was made by kintaro azura chaniago from bencoolen city, indonesia.

Downloads

7

Readme

Noda-fw

This framework was made by kintaro azura chaniago from bencoolen city, indonesia.

Instalation

$ npm install noda-fw

or you can do this

$ npm install github:kintaroazurachaniago/noda-fw

Quick Start

Create one index file. here we create new one index file named "index.js" in the root directory of the project

// getting noda-fw from node_modules
const { Start, Route, Controller } = require('noda-fw')
const { home } = Controller

// register visitable routes
Route.get('/', home.index)

// starting the project
Start(Route, 4120, _ => console.log('Server running on port 4120'))

that's all.

and then try to run this file by execute this command

$ node index

the output in the console should be like this

Server running on port 4120
Database exist!         :       Using "app" database
Table exist!            :       Using "users" table
Working on C:\coding\Space\Tutorial\Nodejs\v1

Now you can try to visite http://127.0.0.1:4120 on your browser app.

How to use?

Route

Route object has two method which is get() and post(). both of them need two parameter which is the url as the first one and the callback as the second one. look at here

// Get method
Route.get('/user/create', (req, res) => {
  res.end(`<form action="/user/save" method="post"><input type="text" name="username"/><button>Create</button></form>`)
})

// Post method
Route.post('/user/save', (req, res) => {
  res.end(JSON.stringify(req.form))
})

Controller

We can store the second parameter of Route.get() and Route.post() method into the other module which is called Controller. in this controller we just need to export the callbacks. and we can also use the local-db as well in the controller file

module.exports = {

  // Controller.home
  home : {
  
    // Controller.home.index
    index : (req, res) => {
      res.end('Hello world')
    }
    
  },
  
  user : {
  
    create : (req, res) => {
      res.end(`<form action="/user/save" method="post"><input type="text" name="username"/><button>Create</button></form>`)
    },
    
    save : (req, res) => {
      res.end(JSON.stringify(req.form))
    }
    
  }
  
}

and actually we better use res.view() insted of res.end(). res.view() will be reading a file and the execute res.end() with the file content which is has been parsed from noda-template-engine and bring the data for the client as well

  module.exports = {
    home : {
      index : (req, res) => {
        /*
        the first parameter is the file's path
        we need to prepare the file before read it. the file should be written in the process.cwd() and then setting.paths.view folder.
        we can change the default views path in the setting.json file by changing the value of setting.paths.view
        the second parameter is the data which is will be passed to the noda-template-engine. and then we can use the data in the view file
        */
        res.view('home.spa', { title : 'Home page', theme : { bg : 'dark', color : 'light' } })
        /*
        data.title       = 'Home page'
        data.theme.bg    = 'dark'
        data.theme.color = 'light'
        */
      }
    }
  }

Noda-template-engine

How do we use the data from server in the view file? We have two ways to manage and modify the data from the server. they are echo-tag and script-tag

| Echo tag | Script tag | | :--------: | :----------: | | Echo tag is focused for print the data into the client | Script tag is focused for modify the data by the conditioner | | -={ /* data / }=- | -=[ / code */ ]=- |

Example :

<div class="row">
  -=[
    const fruits = ['apple', 'mango', 'banana']
    fuits.forEach( fruit => {
      echo(`<div class="col-md-4">Fruit name : ${fruit}</div>`)
    })
  ]=-
</div>

or we can type like this

<div class="row">
  -=[ const fruits = ['apple', 'mango', 'banana'] ]=-
  -=[ fruits.forEach( fruit => { ]=-
  -={ `<div class="col-md-4">Fruit name : ${fruit}</div>` }=-
  -=[ }) ]=-
</div>

Model

Noda-fw comes with local-db manager. Local-db file stored in node_modules/noda-fw/DATABASE.ben directory. We can modify the file content using Model object. Model object has some method such as create(), read(), update(), delete() as CRUD. and where() as well as selector Model object will given when we call DB.createDatabase() method. Noda-fw has DB class, so just require the module

const { DB } = require('noda-fw')

Anyway, Both of DB class and Model class should be used in synchronous programming

Example :

const User = async _ => {
  return await DB.createDatabase('user')
}

Then we can call Model modthods

  • User.create(data)
  • User.read(field)
  • User.update(newData)
  • User.delete()

Just becareful when we use update and delete, it will affect to all of selected table data. unless we define the selected data using where()

  • User.where('id', 1).update({ age : 14 })
  • User.where('age', '>', '18').delete()

I think it's enough for creating a small scale project in nodejs.

If you have a question, Please contact me on :

Thank you very much for your participation :)