1.4.0 • Published 4 years ago

directz v1.4.0

Weekly downloads
12
License
ISC
Repository
github
Last release
4 years ago

Map your REST routes from your services folder and file structure.

Create a empty node project.

mkdir myapp && cd myapp

Install

npm init
npm install express cookie-parser directz

Create the following folder and file structure inside your project folder:

services
|   products.js

In the products.js file past the following code:

module.exports.find = function () {
  return [
    { name: "iPhone X" }, 
    { name: "Samsung S8" }, 
    { name: "Xiaomi MI 8" }
  ];
};

And finally, the index.js file:

const { connect } = require("directz");
const express = require('express');
const cookieParser = require('cookie-parser');

const app = express();
const port = 3000;
const dir = `${process.env.PWD}/services`;
const createRouter = express.Router; 

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());

// create REST routes from your directory and files
connect({ app, dir, createRouter });

app.listen(port, () => console.log(`listening on port ${port}!`));

Run your app

node index.js

Access your app

http://localhost:3000/products

Mapping actions to products.js, for instance:

GET /products >>> find
GET /products/ >>> find

GET /products/:id >>> findOne

POST /products >>> insert

PUT /products/:id >>> update
PATCH /products/:id >>> update

POST /products >>> save
PUT /products/:id >>> save
PATCH /products/:id >>> save

DELETE /products/:id >>> remove
1.4.0

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago