Giter VIP home page Giter VIP logo

beersample-node's Introduction

Beers and Breweries application using node.

This is a sample web application written with the node.js and couchnode library.

We are using couchnode library for accessing couchbase database. Installing couchnode is not straight forward as it uses libcouchbase and a C++ binding to libcouchbase. Refer to couchnode project for installation instructions.

Make sure that you connect with a valid couchbase server and have the beer-sample bucket installed. beer_designs.js sets up view design docs used by this application. To setup the additional design documents,

node beer.js --setup     // --setup switch will setup the design document.

Following is the gist of what the map function does with beer documents,

beer/by_name:

function(doc, meta) {
    if (doc.type && doc.type == "beer") {
        emit(doc.name, null);
    }
}

Following is the gist of what the map function does with brewery documents,

brewery/by_name:

function(doc, meta) {
    if (doc.type && doc.type == "brewery") {
        emit(doc.name, null);
    }
}

To run the webapp, simply do:

node beer.js

And connect to localhost:1337

beersample-node's People

Contributors

brett19 avatar prataprc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beersample-node's Issues

Can't find documentation on key functionality

The use of "\u0FFF" on line 210 of beer_app.js doesn't appear to be explained or documented anywhere in the API reference for Couchbase Node.js 2.0 SDK. (Located here: http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.0/)

It is mentioned in the documentation for beersample-node, like so:

The code passes the user's input for the startkey and for the endkey passes the user's input appended with a Unicode \u0FFF value, which for the view engine means “end here.” You need to get used to it a bit, but it’s actually very neat and efficient.

That's hardly an explanation. Where do I go for further documentation on the "view engine"? In the meantime, could someone offer a better explanation of what's going on here?

Basic part of sample doesn't work. With clean setup, cannot edit a beer. Solution included.

If you click on [Edit] for any beer, and edit any field and then press [Save Changes], the following error is printed to the browser:

ReferenceError: rc is not defined
    at done_edit_beer (c:\git\5\beersample-node\beer_app.js:163:13)
    at callbacks (c:\git\5\beersample-node\node_modules\express\lib\router\index.js:164:37)
    at param (c:\git\5\beersample-node\node_modules\express\lib\router\index.js:138:11)
    at param (c:\git\5\beersample-node\node_modules\express\lib\router\index.js:135:11)
    at pass (c:\git\5\beersample-node\node_modules\express\lib\router\index.js:145:5)
    at Router._dispatch (c:\git\5\beersample-node\node_modules\express\lib\router\index.js:173:5)
    at Object.router (c:\git\5\beersample-node\node_modules\express\lib\router\index.js:33:10)
    at next (c:\git\5\beersample-node\node_modules\express\node_modules\connect\lib\proto.js:190:15)
    at Object.staticMiddleware [as handle] (c:\git\5\beersample-node\node_modules\express\node_modules\connect\lib\middleware\static.js:55:61)
    at next (c:\git\5\beersample-node\node_modules\express\node_modules\connect\lib\proto.js:190:15)

Solution

It seems that rc. was erroneously added to the front of rc.doc.brewery_id on line 163 of beer_app.js. Remove the text rc., save the file, and restart the server and the edit feature now works.

  db.get( rc.doc.brewery_id, function(err, result) {

becomes

  db.get( doc.brewery_id, function(err, result) {

Editing should now work.

Note: I'm really surprised this hasn't been noticed for nearly a year now. Is nobody learning to use Couchbase on Node.js?

Note #2: I really wish there were more sample applications for Node.js, more full-fledged examples that show best practices of using Node.js and of using Couchbase. Samples with production-ready error handling, and samples that are perhaps designed to demonstrate the scalability of couchbase as part of the application (like perhaps some data-processing on statistics or something involving alot of data crunching, maybe GeoSpatial). Perhaps someone could suggest some solid open source projects which do this, for me to look over?

error when editing record

it happens when you try to edit a beer

fix this function

db.get( doc.brewery_id, function(err, result)

at

  function done_edit_beer(req, res) {
    var doc = normalize_beer_fields(req.body);
    //console.log(req.body);

    db.get( rc.doc.brewery_id, function(err, result) {
      if (result.value === undefined) { // Trying to edit non-existing doc ?
        res.send(404);
      } else {    // Set and redirect.
        db.set( req.params.beer_id, doc, function(err, doc, meta) {
          res.redirect('/beers/show/'+req.params.beer_id);
        })
      }
    });
  }

ReferenceError: rc is not defined
at done_edit_beer (/var/node/beersample-node/beer_app.js:157:13)
at callbacks (/var/node/beersample-node/node_modules/express/lib/router/index.js:164:37)
at param (/var/node/beersample-node/node_modules/express/lib/router/index.js:138:11)
at param (/var/node/beersample-node/node_modules/express/lib/router/index.js:135:11)
at pass (/var/node/beersample-node/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/var/node/beersample-node/node_modules/express/lib/router/index.js:173:5)
at Object.router (/var/node/beersample-node/node_modules/express/lib/router/index.js:33:10)
at next (/var/node/beersample-node/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.staticMiddleware as handle
at next (/var/node/beersample-node/node_modules/express/node_modules/connect/lib/proto.js:190:15)

Error running --setup

If there is no "design" in the "beer-samples" bucket called "beer", running node beer.js --setup fails with the following error:

$ node beer.js --setup

c:\git\5\beersample-node\beer_designs.js:37
            if(! ('by_name' in ddoc['views']) ) {
                                   ^
TypeError: Cannot read property 'views' of null
    at c:\git\5\beersample-node\beer_designs.js:37:36
    at c:\git\5\beersample-node\node_modules\couchbase\lib\bucketmgr.js:131:14
    at IncomingMessage.<anonymous> (c:\git\5\beersample-node\node_modules\couchb
ase\lib\bucketmgr.js:11:7)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:943:16
    at process._tickCallback (node.js:419:13)

What's funny is that this condition (having no document found) appears to be handled when the code that follows creates the "brewery" view -- it checks for err and creates a breweries design object. But this check isn't done when creating the "beers" view.

The code should be fixed. However, my workaround was to go to the database administration console, and add a fake view called fake under a design named specifically beer. This results in
node beer.js --setup successfully running, and the application working when started.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.