Giter VIP home page Giter VIP logo

nodejs-form-app's Introduction

bluemix-todo-apps - node version

TodoMVC using Backbone, Mongo and a node back-end, running on BlueMix.

Refer to the README.md file in the parent directory (eg, bluemix-todo-apps/README.md) for general instructions regarding this application and the database service it requires.

This application supports both Mongo DB as a backend.

installation

To run the program, you'll need node.js installed. From a command/shell terminal

  • cd into the parent directory you want to install the project in
  • git clone the project into a child directory
  • cd into that child directory
  • cd into the node directory
  • npm install to install dependencies

For example:

$ cd Projects
$ git clone [INSERT GIT REPO HERE]

    ... git output here ...

$ cd bluemix-todo-apps

$ cd node

$ npm install

    ... npm output here ...

running locally

To run the app locally, you will first need to have a Mongo DB server running locally. The code assumes that the database is using the default port.

After installing the DB server locally, and installing the app via the directions above, you can run it with the command:

node server -d mongo

for Monogo DB.

You should see the following output written to the console:

bluemix-todo-apps-node: VCAP_SERVICES environment is not set
bluemix-todo-apps-node: using database:  http://127.0.0.1:5984/todos
bluemix-todo-apps-node: server starting: http://localhost:6024

You can use the URL listed on the last line to access the application. It stores the data locally in the database listed on the second line.

deploying to BlueMix

To deploy this application to BlueMix you must have the Cloud Foundry command line installed and have logged into BlueMix using the command line.

To use the simple commands below to deploy the application you will also need jbuild installed. It can be installed via npm.

To install jbuild on Windows, use the command

npm -g install jbuild

To install jbuild on Mac or Linux, use the command

sudo npm -g install jbuild

To deploy the Mongo DB version to BlueMix run

$ jbuild deploymongo appName

Replace appName with a unique name for your application. This command will create a Mongo DB service called todos-mongo-db if one does not already exist.

Replace appName with a unique name for your application.

Other commands you may want to use

  • cf logs bluemix-todo-node

    shows continuous log information for the app; Ctrl-C to exit

  • cf logs bluemix-todo-node --recent

    shows recent log information for the app

  • cf stop bluemix-todo-node

    stop the app if it's running

  • cf start bluemix-todo-node

    start the app if it's stopped

  • cf app bluemix-todo-node

    show information about the app

  • cf apps

    show information about all the apps you have

You can of course also do all this through the ACE dashboard as well.

about the application

This application is written in CoffeeScript and compiled into JavaScript. The CoffeeScript source is available in the lib-src directory, and the compiled JavaScript files are available in the lib directory.

The application makes use of the following packages from npm:

  • express

    a framework to build web server applications

  • nopt

    a library to parse command-line arguments

  • ports

    a library to consistently manage name http ports

  • q

    a promises library

  • underscore

    a utility belt library with lots of handy functions

  • monk

    a library to interface with Mongo DB

###promises###

This application makes heavy use of Q promises to handle async calls. Promises are explained in depth on Q's project page and an introduction to promises is available at the http://promisejs.org site.

files

  • lib/*

    the JavaScript files compiled from the lib-src CoffeeScript source

  • lib-src/*

    the CoffeeScript files - more detail below

  • node_modules/*

    the pre-req node packages installed when you run npm install

  • tests/*

    some tests that get run as part of the build

  • www/*

    a copy of the files from the parent frontend directory (eg, bluemix-todo-apps/frontend)

  • README.md

    This file!

  • jbuild.coffee

    A file used to build and deploy the application; see the "hacking" topic, below.

  • manifest.yml

    This file sets the attributes for your application when it's deployed.

  • package.json

    This file is used by BlueMix to determine that this is a node application, so that the node.js buildpack is used to deploy the application. It's a standard file for node.js applications anyway, used to determine the pre-req packages your application uses. Eg, npm install uses the dependency lists in the file to determine which packages to install from npm.

  • server.js

    A simple program to launch the application.

CoffeeScript files

The following files are the source files for the application, available in the lib-src directory. Below is a brief description of the files.

  • cli.coffee

    Handles the command-line invocation of node server; parses the command line and constructs a call to the server module.

  • mongo-db.coffee

    Handles interaction with the Mongo database. A DB object is created to handle the interaction, which has a set of SCRUD methods (search/create/read/update/delete) to access the data.

  • server.coffee

    Handles the HTTP server

  • tx.coffee

    Provides a transaction object which turns HTTP requests into Database operations.

  • utils.coffee

    Provides some utility functions used in all the modules.

hacking

If you want to modify the source to play with it, you'll also want to have the jbuild program installed.

To install jbuild on Windows, use the command

npm -g install jbuild

To install jbuild on Mac or Linux, use the command

sudo npm -g install jbuild

The jbuild command runs tasks defined in the jbuild.coffee file. The task you will most likely use is watch, which you can run with the command:

jbuild watch

When you run this command, the application will be built from source, the server started, and tests run. When you subsequently edit and then save one of the source files, the application will be re-built, the server re-started, and the tests re-run. For ever. Use Ctrl-C to exit the jbuild watch loop.

You can run those build, server, and test tasks separately. Run jbuild with no arguments to see what tasks are available, along with a short description of them.

license

Apache License, Verison 2.0

http://www.apache.org/licenses/LICENSE-2.0.html

nodejs-form-app's People

Contributors

jasonlanderson avatar

Watchers

 avatar

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.