Skip to content

Repository files navigation

node-loopie NPM versionNPM monthly downloadsNPM total downloads

Reduce your code with node-loopie. Routes declaration, models, and etc... node-loopie will shorten it for you. Converts your nodejs files in a folder to an object.

  • Declarative: node-loopie helps you shorten your code, you don't have to declare multiple properties to export your object or even initialize function(s). It makes recognition of objects easier with just looking at your file names.

Installation

Install with npm:

$ npm install --save node-loopie

Usage

Arguments

nl(folder_path, callback, ignore_file_names, extension_name)

  • folder_path (required) : [String] folder path of the files you want to loop.
  • callback : [Function] function to be executed. passes 3 arguments: file [String], filename [String], file [File].
  • ignore_file_names : [Array (String)] array of file names to be ignored in a folder.
  • extension_name extension name of the files you want to loop from.

Examples

Sequelize (index.js)

constLoopie=require('node-loopie');constpath=require('path');constSequelize=require('sequelize');constenv=NODE_ENV||'localhost';constconfig=require('/../config/config.js')[env];constdb={};letsequelize;if(config.use_env_variable){sequelize=newSequelize(process.env[config.use_env_variable],config);}else{sequelize=newSequelize(config.database,config.username,config.password,config);}// Get all the filename inside the models folderLoopie(__dirname,(file)=>{constmodel=require(path.join(__dirname,file))(sequelize,Sequelize.DataTypes);db[model.name]=model;});Object.keys(db).forEach((modelName)=>{if(db[modelName].associate){db[modelName].associate(db);}});db.sequelize=sequelize;db.Sequelize=Sequelize;module.exports=db;

Express Routes (index.js)

constexpress=require('express');constLoopie=require('node-loopie');constapp=express();Loopie(__dirname,(file,fileName)=>{app.use(`/api/${fileName}`,require(path.join(__dirname,file)));});

Author

Axl Cuyugan

License

Released under the ISC License.


About

Reduce your code with node-loopie. Routes declaration, models, and etc... node-loopie will shorten it for you. Converts your nodejs files in a folder to an object.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages