Deployd's Server
extends node's http.Server
. A Server
is created with an options object that tells Deployd what port to serve on and which database to connect to.
The Server
object is also the main entry point for modules. After it is started, the Server
instance is available at process.server
.
Servers are created when calling the Deployd exported function.
var deployd = require('deployd')
, options = {port: 3000}
, server = deployd(options);
options
{Object}
port
{Number} - the port to listen ondb
{Object} - the database to connect todb.connectionString
{String} - The URI of the mongoDB using standard Connection String. If db.connectionString
is set, the other db options are ignored.port
{Number} - the port of the database serverhost
{String} - the ip or domain of the database servername
{String} - the name of the databasecredentials
{Object} - credentials for the server
username
{String}password
{String}env
{String} - the environment to run in.Note: If options.env
is "development", the dashboard will not require authentication and configuration will not be cached. Make sure to change this to "production" or something similar when deploying.
Load any configuration and start listening for incoming connections.
var dpd = require('deployd')
, server = dpd()
dpd.listen();
dpd.on('listening', function() {
console.log(server.options.port); // 2403
});
Create a new Store
for persisting data using the database info that was passed to the server when it was created.
// Create a new server
var server = new Server({port: 3000, db: {host: 'localhost', port: 27015, name: 'my-db'}});
// Attach a store to the server
var todos = server.createStore('todos');
// Use the store to CRUD data
todos.insert({name: 'go to the store', done: true}, ...); // see `Store` for more info
An Array
of the server's Resource instances. These are built from the config and type loaders.
deployd.attach can attach Server Class functions into a regular http server. It also provide handleRequest
function to act as express middleware.
var deployd = require('deployd')
, options = {}
, server = require('http').createServer(app)
, server = deployd.attach(server, options);
options
{Object}
socketIo
{Object} - socket.io instancedb
{Object} - the database to connect toport
{Number} - the port of the database serverhost
{String} - the ip or domain of the database servername
{String} - the name of the databasecredentials
{Object} - credentials for the server
username
{String}password
{String}env
{String} - the environment to run in.Note: If options.env
is "development", the dashboard will not require authentication and configuration will not be cached. Make sure to change this to "production" or something similar when deploying.
Let us know if you have any ideas to improve our docs. Open an issue on github, send us an email, or tweet us.
This entire site, including documentation written in markdown is available on github. Pull requests are appreciated!