Node.js full-stack web framework Symfony Like Starter
Clone or download
Latest commit acf69ef Oct 12, 2018

README.md


NODEFONY V4

npm package

Issues Status Build Status CII Best Practices

Nodefony is Node.js full-stack web framework.

Nodefony can be used to develop a complete solution to create a web application.

The Nodefony project is inspired by the PHP Symfony framework, a developer can find most of the concepts, configurations and patterns of Symfony framework.

Nodefony is not an exhaustive port of symfony !

Table of content

Nodefony features :

  • Servers (http(s), websocket(s), statics, sockjs)
  • HTTP2 http2 ready node module provides an implementation of the HTTP/2 (push server ready).
  • Dynamics routing
  • ORM (Sequelize, mongoose)
  • Simple Databases connection (mongo, ...)
  • MVC templating (Twig)
  • Notion of real-time context in Action Controller (websocket).
  • Notion of synchronous or asynchronous execution in Action Controller (Promise).
  • Services Containers, Dependency Injection (Design Patterns)
  • Sessions Manager (ORM, memcached)
  • Authentication Manager (Digest, Basic, oAuth, Local, ldap, jwf)
  • WAF ( Web application firewall )
  • Cross-Origin Resource Sharing (CORS)
  • Production Management (PM2)
  • RealTime API (Bayeux Protocol)
  • Webpack Assets management (Like WDS with HMR hot module Replacement)
  • C++ Addons (Binding in Bundle)
  • Translations
  • CLI (Command Line Interface)
  • Monitororing , Debug Bar
  • Unit Test Api in framework context (MOCHA)

Nodefony assimilates into the ecosystem of node.js with services like :

  • WEBPACK Module bundler for assets management of application .
  • SockJS Server ( Like WDS 'Webpack Dev Server' and HMR management )
  • WATCHER node.js for auto reload-files in developement mode .
  • PM2 Production Process Manager for Node.js .
  • Passport Simple, unobtrusive authentication for Node.js .
  • Angular Experimental Bundle Generator ( Angular cli no longer allows the ejection of a webpack config)
  • React Experimental Bundle Generator ( Now an React Project can be merge into a Nodefony Bundle )
  • Vue.js Experimental Bundle Generator ( Now an Vue.js Project can be merge into a Nodefony Bundle )

Nodefony 4 adds the following features :

  • C++ Addons (Binding in Bundle)
  • Authorisations
  • HTTP2
  • WEBPACK 4

Now in this version 4 Beta, Nodefony is evolved to a stable version without major fundamental changes.

Evolution priorities up to the stable version will focus on robustness, unit testing, documentation and security.

Nodefony is ported with ECMAScript 6 ( Class, Inheritance ).

You can follow Nodefony build on travis at https://travis-ci.org/nodefony/nodefony

Resources for Newcomers

- Nodefony Demo

- Nodefony Documentation

- Nodefony Monitoring

Documentation in progress !!

Requirements

On your system you must have Installed :

  • GIT is Distributed version control system

  • Node.js ® is a Platform built on Chrome's JavaScript runtime ( >= 8 )

  • npm or yarn Packages Manager for javascript application

  • OpenSSL Toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols

  • GNU Bash Bash is the GNU Project's shell

Operating Systems : Install Node.js via Package

  • LINUX

    • Debian, Ubuntu (Checked, Tested)
    • RASPBIAN Raspberry Pi (Checked)
  • MACOS (Checked, Tested)

  • FreeBSD (Checked)

    • pkg install bash rsync gmake gcc6
    • setenv CC "/usr/local/bin/gcc"
    • setenv CXX "/usr/local/bin/g++"
    • cd /usr/local/bin/ ;ln -s pythonx.x python
  • OpenBSD (Not Checked yet )

  • WINDOWS (Not ported yet )

  • ELECTRON Experimental Nodefony Electron ( Now an Electron Context can be use in Nodefony Project )

  • EMBEDDED SYSTEM ( Very difficult : large memory footprint )

Install

Install Node.js :

  • nvm Node Version Manager - Simple bash script to manage multiple active node.js versions

To install or update nvm, you can use the install script using cURL:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

or Wget:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Install Nodefony Excutable (globally) :

npm -g install nodefony

# or with yarn

yarn global add nodefony

likely error :

Build Project with nodefony cli (recommended):

#  CLI generate project name : myproject

$ nodefony create myproject
$ cd myproject

Cli Usage :

$ nodefony -h
nodefony                                                                                              
    create [-i] name [path]                       Create New Nodefony Project                  

# OR YOU CAN USE CLI INTERACTIVE MODE (nodefony without args)

$ nodefony
 _   _    ___    ____    _____   _____    ___    _   _  __   __
| \ | |  / _ \  |  _ \  | ____| |  ___|  / _ \  | \ | | \ \ / /
|  \| | | | | | | | | | |  _|   | |_    | | | | |  \| |  \ V /
| |\  | | |_| | | |_| | | |___  |  _|   | |_| | | |\  |   | |  
|_| \_|  \___/  |____/  |_____| |_|      \___/  |_| \_|   |_|  

Version : 4.0.0-beta.5 Platform : darwin Process : nodefony PID : 16368

?  Nodefony CLI :  (Use arrow keys)
❯ Create Nodefony Project
  PM2 Tools
  --------
  Help
  Quit

Build Project with Github Starter :

#  Clone nodefony starter

$ git clone https://github.com/nodefony/nodefony.git
$ cd nodefony
$ nodefony build

Cli Usage :

# OR YOU CAN USE CLI INTERACTIVE MODE TO BUILD PROJECT (nodefony without args)
$ nodefony
             _   _    ___    ____    _____   _____    ___    _   _  __   __
            | \ | |  / _ \  |  _ \  | ____| |  ___|  / _ \  | \ | | \ \ / /
            |  \| | | | | | | | | | |  _|   | |_    | | | | |  \| |  \ V /
            | |\  | | |_| | | |_| | | |___  |  _|   | |_| | | |\  |   | |  
            |_| \_|  \___/  |____/  |_____| |_|      \___/  |_| \_|   |_|  


         Version : 4.0.0-beta.6 Platform : darwin Process : nodefony PID : 51362

Fri Sep 14 2018 14:46:14 INFO nodefony : WELCOME PROJECT : myproject 1.0.0
?  Nodefony CLI :  (Use arrow keys)
❯ Build Project
 Generater
 Tools
 PM2 Tools
 --------
 Help
 Quit

Serving a Nodefony project via an development server

Starting Development Servers :

$ nodefony dev

# TO STOP
$ <ctrl-c>

Starting Development Servers in Debug Mode (-d) :

$ nodefony -d dev

# TO STOP
$ <ctrl-c>
# OR YOU CAN USE CLI INTERACTIVE MODE (nodefony without args)
 _   _    ___    ____    _____   _____    ___    _   _  __   __
| \ | |  / _ \  |  _ \  | ____| |  ___|  / _ \  | \ | | \ \ / /
|  \| | | | | | | | | | |  _|   | |_    | | | | |  \| |  \ V /
| |\  | | |_| | | |_| | | |___  |  _|   | |_| | | |\  |   | |  
|_| \_|  \___/  |____/  |_____| |_|      \___/  |_| \_|   |_|  

Version : 4.0.0 Platform : linux  Process : nodefony PID : 31635

Fri Jul 27 2018 17:01:11 INFO nodefony : WELCOME PROJECT : myproject 1.0.0

?  Nodefony CLI :  
❯ Start Servers Development
  Start Servers Pre-Production
  Start Servers Production
  Install Project
  Rebuild Project
  Generater
  Tools
  PM2 Tools
  Run Test
  --------
  Help
  Quit

Starting Development Servers in Inspector mode (--inspect) :

Nodejs Debugging Guide

$ npm -g install npx

$ npx --node-arg=--inspect nodefony dev

# check chrome://inspect in your browser

Serving a Nodefony Project via a Production server :

Starting a Nodefony project with PM2 :

$ nodefony prod

Tools PM2 You can see PM2 config : config/pm2.config.js

# To See log
$ nodefony logs

# To List Status of Production projects
$ nodefony list

# TO KILL PM2 DEAMON
$ nodefony kill

# TO STOP APPLICATION WITHOUT KILL PM2 DEAMON
$ nodefony stop

Checking a Nodefony Project Pre-Production (Usefull to check Clusters Node) :

$ nodefony preprod

Serving a Nodefony project with HTTPS

By default nodefony listen secure port in 5152 @see config/config.yml

During the installation process all the openssl parts were generated ( self-signed localhost certificate ).

You can Change default openssl configuration in :

config/openssl

You must Add a Trusted CA in your Browser : projectName-root-ca.crt.pem You can find certificate authority (ca) here:

config/certificates/ca/projectName-root-ca.crt.pem

Access to Secure App with URL : https://localhost:5152

Access to App with URL : http://localhost:5151

nodefony

Framework Configurations

Open config/config.yml if you want change httpPort, domain ,servers, add bundle, locale ...

#####################
#  NODEFONY FRAMEWORK
#
#       KERNEL CONFIG
#
#   Domain listen : Nodefony can listen only one domain ( no vhost )
#     Example :
#      domain :  0.0.0.0      # for all interfaces
#      domain :  [::1]        # for IPV6 only
#      domain :  192.168.1.1  # IPV4
#      domain :  mydomain.com # DNS
#
#   Domain Alias : string only "<<regexp>>" use domainCheck : true
#     Example :
#      domainAlias:
#        - "^127.0.0.1$"
#        - "^localhost$"
#        - ".*\\.nodefony\\.com"
#        - "^nodefony\\.eu$"
#        - "^.*\\.nodefony\\.eu$"
#
system:
  domain                        : 0.0.0.0
  domainAlias:
    - "^127.0.0.1$"
    - "^localhost$"
  httpPort                      : 5151
  httpsPort                     : 5152
  domainCheck                   : true
  statics                       : true
  security                      : true
  realtime                      : true
  monitoring                    : true
  documentation                 : true
  unitTest                      : true
  demo                          : true
  locale                        : "en_en"
  servers:
    protocol                    : "2.0"             #  2.0 || 1.1
    http                        : true
    https                       : true
    ws                          : true
    wss			                    : true
    certificats:
      key                       : "config/certificates/server/privkey.pem"
      cert                      : "config/certificates/server/fullchain.pem"
      ca                        : "config/certificates/ca/projectName-root-ca.crt.pem"
      options:
        rejectUnauthorized      : true
  devServer:
    inline                      : true
    hot                         : false
    hotOnly                     : false
    overlay                     : true
    logLevel                    : info        # none, error, warning or info
    progress                    : false
    protocol                    : https
    websocket                   : true
  bundles:
    hello-bundle                : "file:src/bundles/hello-bundle"

Quick Start

Install Nodefony :

$ npm -g install nodefony

See Global install How to Prevent Permissions Errors

Install Project :

$ nodefony create myproject
$ cd myproject

Generating a New Bundle :

CLI Generate new bundle : default path src/bundles

$ nodefony generate:bundle name [path]

# Or Generate a New Bundle Interactive
$ nodefony

?  Nodefony CLI :  Generater
?  Nodefony CLI :  (Use arrow keys)
❯ Generate New Bundle
  Generate New Controller
  Generate New Service
  Generate New Entity
  Generate New Nodefony Project
  Generate Openssl Certificates
  Generate Haproxy Configuration
  Generate Nginx Configuration
  Generate letsEncrypt Webroot Configuration
  --------
  Quit

Starting Servers to check new Bundle hello:

$ nodefony dev

Access to bundle route with URL : http://localhost:5151/hello

Access to bundle route with URL : https://localhost:5152/hello

Now hello-bundle is auto-insert in framework with watcher active and auto-config Webpack Module bundler

Example controller : src/bundles/hello-bundle/controller/defaultController.js

module.exports = class defaultController extends nodefony.controller {
  constructor (container, context){
    super(container, context);
  }
  indexAction() {
    try {
      return this.render("hello-bundle::index.html.twig", {
        name: "hello-bundle"
      });
    } catch (e) {
      throw e;
    }
  }
};

Example view (twig) : src/bundles/hello-bundle/Resources/views/index.html.twig

{% extends '/app/Resources/views/base.html.twig' %}

{% block title %}Welcome {{name}}! {% endblock %}

{% block stylesheets %}
  {{ parent() }}
  <!-- WEBPACK BUNDLE -->
  <link rel='stylesheet' href='{{CDN("stylesheet")}}/hello-bundle/assets/css/hello.css' />
{% endblock %}

{% block body %}
      <img class='displayed' src='{{CDN("image")}}/framework-bundle/images/nodefony-logo-white.png'>
      <h1 class='success'>
        <a href='{{url('documentation')}}'>
          <strong style='font-size:45px'>NODEFONY</strong>
        </a>
        <p>{{trans('welcome')}} {{name}}</p>
      </h1>
{% endblock %}

{% block javascripts %}
  {{ parent() }}
  <!-- WEBPACK BUNDLE -->
  <script src='{{CDN("javascript")}}/hello-bundle/assets/js/hello.js'></script>
{% endblock %}

watchers :

The bundle generation engine build bundle config with node.js watcher configuration

In developement mode is very usefull to auto-reload files as controllers , views , routing , translations

without having to reboot the server.

You can see hello-bundle config : src/bundles/hello-bundle/Resources/config/config.yml

########## nodefony CONFIG BUNDLE  hello-bundle  ############
name :                          hello-bundle
version:                        "1.0.0"
locale :                        en_en

#
#  WATCHERS
#
#    watchers Listen to changes, deletion, renaming of files and directories
#    of different components
#
#    For watch all components
#
#      watch:			true
#    or
#      watch:
#        controller:	true
#        config:        true		# only  routing
#        views:         true
#        translations:  true
#        webpack:       true
#        services:      true
#
watch:                          true

Webpack Module bundler :

The bundle generation engine build bundle config with a predefined webpack configuration

In this way webpack is very usefull to manage all assets of bundle

In developement mode watch is very usefull to auto-compile webpack module bundle

without having to reboot the server

You can see hello-bundle config webpack : src/bundles/hello-bundle/Resources/config/webpack.config.js

module.exports = webpackMerge({
  context: context,
  target: "web",
  entry       : {
    hello  : [ "./js/hello.js" ]
  },
  output: {
    path: public,
    publicPath: publicPath,
    filename: "./js/[name].js",
    library: "[name]",
    libraryTarget: "umd"
  },
  externals: {},
  resolve: {},
  module: {...}
});

Monitoring FRAMEWORK

Access to monitoring route with URL : http://localhost:5151/nodefony

MONITORING

Monitoring in progress !!!

Who Use Nodefony:

SFR ALTICE

Big thanks:

  • D-Lake French specialist in infrastructure and data security.

Related Links:

More informations Nodefony Documentation

Authors

License

CeCILL-B

Demo

Demo