quick-server

0.5.1 • Public • Published

Quick-Server

Is web server helper for NodeJS/Express/Hogan and can be run directly or require'd into a script.
Its for doing stuff, without all the boilerplate.

Install

$ npm install quick-server
OR
$ npm install quick-server -g
$ quick-server

Require into a script - all params are optional

require('quick-server')({
    port: 4000, 
    ip:'127.0.0.1', 
    session:'mysesskey', 
    errors: 1,
    ssl:'myhost.com',
    logport: 8081,
    debug: 1
}, function(app){
    console.log(app.debug);
})

Use env instead of options

test.js --
require('quick-server')(null, function(app){
    console.log(app.debug);
})

$ port=81 node test.js

Hogan/Mustache.js rendering

app.hogan(template_filename, obj)  --OR--
res.render(template_filename, obj)

s.return

// Return NodeJS style error/results object to browser

app.get('/api/name', function(r, s){
    s.return(null, {name: 'quicker'});
})
  ** to browser ==> {e:null, {r: {name:'quicker'}}}

s.render

// Takes file name or string as a template

app.get('/', function(r, s){
    s.render('Hi {{name}}', {name: 'there'});
})

Experimental support for partials..

index.html

Hi there {{>part.html}}

part.html

{{name}}, how ru?

server.some.js

module.exports = function(options, app){
    console.log('module loaded');

    app.get('/s', function(r, s){
        s.render('index.html', {name: 'chris'});
    })
}

Use Express sessions

$ session=mysecretisthis quick-server

SSL

$ ssl=mydomain.com quick-server

OR

Two steps to run as SSL/HTTPS server:

1)
require('quick-server')({ssl: 'mydomain.com'}, function(options, app){
    ...
}

2)
Put these files in the current directory:

mydomain.com.key
mydomain.com.intermediate.crt (called gd_bundle if gotten from GoDaddy)
mydomain.com.cert

Logging in browser

require('quick-server')({ logport: 8081 }, function(app){
    ...
})

// In HTML
<script src='/log'></script>

log();  	// Server Console.Log is now websocketed to the browser
            // view in the browser console
logstop();  // Stop that

Browser JS

// In HTML

// JQuery, Bootstrap JS, and the helpers below
<script src='/j.js'></script>

// localStorage helpers
_localStorage.set = function(n, o)
_localStorage.get = function(n)
_localStorage.array = function(n, f, p)

// client-side Mustache rendering
_render(template, object, callback)

// time helper
_time(); dosomething(); _time(); // displays time it takes to dosomething

// Websocket client - server should send node style {e: error, r: result}
_ws('ws://localhost:8081', function(e, r){
    if(e) throw(e);
    console.log(r);
})

// POST - quick-server s.returns node style error, results
_post = function(url, data, function(e, r){
    if(e) throw(e);
    ...
})

// JQuery helpers

<div id='mydiv'></div>

$('#mydiv').render('Hello {{name}}', {name: 'there'})

.renderLocal('Hello {{name}}')  // localStorage key mydiv = {name: 'there'}
.renderPost('Hello {{name}}', 'http://localhost/api/getsometh', {value: 'name'})
.renderSocket('Hello {{name}}', 'ws://localhost:8081')  // socket gets object and renders to templ

Readme

Keywords

none

Package Sidebar

Install

npm i quick-server

Weekly Downloads

6

Version

0.5.1

License

none

Last publish

Collaborators

  • dpweb