express-couchdb-router

0.2.3 • Public • Published

express-couchdb-router

Purpose

This is an express router which allows you to store your static files in a CouchDb database instead of in the file system. This is useful when your website has a mixture of static and dynamic content. It means the entire website is contained within the database and can easily be replicated for redundancy, scaling and offline use.

Tools are included to enable you to develop locally in the file system and then upload to the database.

Status

Alpha testing. This is still very much a "work-in-progress". Fell free to try it and make suggestions but do not use it in production just yet.

Set Up

npm install express-couchdb-router

Once installed run the ECR utility, ecr init, to initialise your workspace.

app.js

This has the Express based web app. The sample provided allows you to choose whether to run from the local static files (command line option -s or --static) or the database (command line option -d or -database).

Example

node ./app.js -s will use the static files.
node ./app.js -d will use the database.

Static Folder

This is the folder where you will develop the static files used by your website. This would not normally be copied to the production server.

NPM Scripts

The following scripts are added to the package.json:

  • static - Runs the server from the local static files.
  • localdb - Runs the server from the local database. These are implemented using npm run <script name>.

Configuration File

The configuration file, ecr-config.json, is created as part of the init process. This should be amended as needed by your particular app. The default values will get you started

{
  "localDb": { <--- Defines the local database used for testing and staging.
    "URL": "http://localhost:5984/<your app name>",
    "adminName": (optional) <--- The name of the admin user
    "adminPassword": (optional) <--- The password of the admin user
  },
  "prodDb": { <--- Defines the production database. Not used at the moment.
    "Url": (optional),
    "admin": (optional),
    "password": (optional)
  },
  "staticFolder": "./static" <--- The local folder where the static files are stored.
}

The database server is initialised as the localhost with the application name (as defined in package.json) for the database name.

Upload

The local database can be synchronised to the local static files using the command:
ecr upload
This will copy all the static files into the local database and remove any entries in the database which no longer have matching entries in the static files folder.

This allows for a staging test running from a local database before replicating the local database to the producion database.

Contributions

Pull requests accepted

Author

Mike Robertson mike@soligeo.scot

Readme

Keywords

none

Package Sidebar

Install

npm i express-couchdb-router

Weekly Downloads

1

Version

0.2.3

License

MIT

Unpacked Size

19.8 kB

Total Files

9

Last publish

Collaborators

  • mike4ql