AhmedAli7O1 / arch

:tada: a Tool to Manage & Automate your Node.js Server :tada:
https://www.npmjs.com/package/nodearch
MIT License
14 stars 0 forks source link
architecture cli flow framework manage mvc nodejs structure
NodeArch Logo manage and generate a powerful fully organized and customizable node.js server of your choice build, generate, edit, and share your project design and flow with your team prebuilt extensions and tools to help you focus on your business idea Maintainer: [Ahmed Ali](https://github.com/AhmedAli7O1) ![build](https://travis-ci.org/nodearch/arch.svg?branch=master) ![npm](https://img.shields.io/npm/v/nodearch.svg)



Content


Introduction:

nodearch is a set of libraries, that help you not just getting up and running fast, but also helping to manage your application structure, environment specific configurations, prebuilt set of extensions to help you using tools and third parties out of the box, and you gotta break down your business irrelevant logic into your own defined extensions that register themselves on nodearch load flow, and of course break down your business logic code into separate plugins, and each plugin consist of a collection of components.


Differences:


How it Works

what is what?

the flow

the image below describes it as well:

![NodeArch Flow](https://raw.githubusercontent.com/nodearch/arch/master/resources/nodearch-flow.png)

Getting Started

let's start by installing the NodeArch CLI tool by

npm i -g nodearch

now it's simple as generating a full example project by

nodearch g

then choose your prefered nodejs framework, press enter and the CLI tool will start preparing a new project for you, by creating your folders structure, downloading the required modules to integrate your chosen framework, and finally runs npm install for you, once all this done, you can safely go to your new project folder and run npm start or npm test

Available Examples

Configuration

​ example: if NODE_ENV = "develpoment", then the configuration folder should contain a development folder.


Extensions

Example for a before function to use mongoose to initialize database connection.

'use strict';

const _ = require('lodash');
const mongoose = require('mongoose');
mongoose.Promise = Promise;

const { config, log } = require('nodearch');

module.exports = {

  before: function () {
    return new Promise((resolve, reject) => {

      if (!config || !config.mongoose) {
        return reject(new Error('mongoose configurations not found!'));
      }

      const { url, options } = config.mongoose;

      if (!url) {
        return reject(new Error('mongo url not found in the mongoose configuration file!'));
      }

      mongoose.connect(url, options);

      const db = mongoose.connection;
      db.on('error', (err) => reject(err));

      db.once('open', () => {
        log.info('Connected To MongoDB');
        return resolve(db);
      });

    });
  }
};

Install Extensions

nodearch add

Available Extensions


Share Your Extensions

if you already wrote an extension, and you'd like to share it with us, publish it as npm module on npmjs and add nodearch-extension in the keywords list so we can find it within the nodearch cli

Main Project


Index


nodearch.json


Other Features


CLI

Install Node Arch globally

npm i -g nodearch

Commands:

start     # alias (s) # start server that exist in the current or parent directory
console   # alias (c) # start server that exist in the current or parent directory in interactive mode
add       # alias (a) # add nodearch extension
remove    # alias (r) # remove nodearch extension
generate  # alias (g) # generate full and ready to go nodearch example

Example: nodearch console

Console

nodearch console does actually run your app in an interactive console Node.js Repl and exposes a global reference nodearch identical to the resulting object from const nodearch = require('nodearch'); which contains all your project dependencies, extensions...etc

this means your app will still functional and listen for incoming connections as usual the only difference is the terminal will be interactive, think of it as the Google Chrome's console, where you can interact live with your application scope while running.

nodearch console can be used from the root app directory or any sub/nested directory in your app.

Usage Examples:

running specific function in your project for testing purposes

# run console
nodearch console
# execute any function in your app
nodearch> nodearch.deps.userPlugin.services.UserService.find().then(res => console.log(res));
# here is the result
nodearch> [ { _id: 5ae4cea2f9d3d23b724eb125,
    name: 'user one',
    age: 20} ]

try to log your current loaded configurations

nodearch console
nodearch> nodearch.config


sponsored by:
Trufla