node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »


pineapple pineapple pineapple pineapple pineapple

Build Status

A MVC based, yet arguably liberal RESTful API framework. Includes routing, controllers, models, utilities, and a MongoDB interface.

pineapple pineapple pineapple pineapple pineapple

Table of Contents

pineapple pineapple pineapple pineapple pineapple



pineapple requires global installation for the CLI utilitiy. If you do not plan on using pineapple to manage a pineapple application from the command line then using it as a local module is fine.

$ [sudo] npm install -g pineapple


pineappleCreating a new app

pineapple gen <name>

Creating a pineapple application can easily be achieved with pineapple gen

$ pineapple gen myapp
[pineapple] => Going to grab all of those dependencies now..
[pineapple] => This may take a while..
[pineapple] => Sweet! I've created a new Pineapple application here => /Users/werle/myapp


pineappleStarting a pineapple server

pineapple server

Starting a pineapple server of a pineapple application is as simple as executing pineapple server from the directory of the pineapple application.


$ pineapple server
Requiring app module /config/environment
Requiring app module /config/development
Requiring app module /config/application
Requiring app module /config/routes.js
Requiring app module /app/controllers
Requiring app module /app/models
[app] => Found the Paplfile file. => /Users/werle/repos/myapp/Paplfile
[server] => Listening on port 4000


You could utilize the pineapple module and create your own server without using a skeleton pineapple application. The contents of the app.js file below whose only dependency is pineapple demonstrates the process of using pineapple in node with minimal requirements. Consider the following app structure:

├── app.js
└── node_modules
    └── pineapple (pineapple module)

You could then use pineapple to create a server, bind routes, and listen on a port to start the service.

// it isn't needed to store pineapple in a variable as it is attached 
// to the global object during its bootstrap 
// define an app name  
var appName = "myService";
// server config 
var serverConfig = {
  config : { 
    name : appName
// Let pineapple no about your app name = appName;
// we can create a server with minimal configuration 
 * In order for your server to work we will need some routes set up.
 * That can easily be achieved with pineapple's built in router.
 * The Router supports basic POST, GET, PUT, and DELETE protocols via
 * convenience methods:
 *, [controller_path|callback]); // POST
 *  router.get(uri_path, [controller_path|callback]); // GET
 *  router.put(uri_path, [controller_path|callback]); // PUT
 *  router.del(uri_path, [controller_path|callback]); // DELETE
 * If you need to set a custom method you can call .create() directly:
 *  router.create(CUSTOM_METHOD, uri_path, [controller_path|callback]);
// we need to create a router instance 
var router = new pineapple.router.Router();
// lets get a "Hello world" going 
router.get('/hello', function(request, response){
  var request  = this.request
    , response = this.response
  // output some sanity 
  pineapple.api.logger.success("Got the request, emitting response..");
  // response with a json response 
    message  : "Hello world! I'm a pineapple api server."
  // Got the request now close the connection 
  pineapple.api.logger.warn("Closing connection..");
  // close the connection 
  // warn pineapples departure 
  pineapple.logger.warn("Exiting pineapple..");
  // exit.. 
  // you never really have to call .exit() directly.. 
// we need to bind the routes we just created to the server 
// once all is said and done, we can finally start the server 
// the .listen() method accept a port and a callback for arguments 
pineapple.api.listen(4000, function(){
  // tap into pineapples api logger"Connected! =)");

From the command line you can then execute the app.js file with the node executable which will output something like this:

$ node app.js
[server] => Connected! =)

From the browser or from a program like cURL you could hit the following url http://localhost:4000/hello while your app is running.

$ curl http://localhost:4000/hello
{"code":200,"status":true,"data":{"message":"Hello world! I'm a pineapple api server."}}


pineappleStarting a pineapple console

$ pineapple console
everybit-local> pineapple.models
{ User: { [Function: User] super: [Function] },
  Profile: { [Function: Profile] super: [Function] },
  CreditCard: { [Function: CreditCard] super: [Function] },
  Video: { [Function: Video] super: [Function] },
  Version: { [Function: Version] super: [Function] },
  Media: { [Function: Media] super: [Function] },
  Image: { [Function: Image] super: [Function] },
  Blurb: { [Function: Blurb] super: [Function] },
  Audio: { [Function: Audio] super: [Function] },
   { User: { [Function: User] super: [Function] },
     Profile: { [Function: Profile] super: [Function] },
     CreditCard: { [Function: CreditCard] super: [Function] } },
   { Video: { [Function: Video] super: [Function] },
     Version: { [Function: Version] super: [Function] },
     Media: { [Function: Media] super: [Function] },
     Image: { [Function: Image] super: [Function] },
     Blurb: { [Function: Blurb] super: [Function] },
     Audio: { [Function: Audio] super: [Function] } },
  getSchema: [Function] }


pineappleBasic app structure

├── Capfile
├── Jakefile
├── Paplfile
├── Procfile
├── app
│   ├── controllers
│   │   ├── Application.js
│   │   ├── index.js
│   │   └── pineapple
│   │       ├── Api.js
│   │       └── index.js
│   └── models
│       └── index.js
├── config
│   ├──
│   ├── application.json
│   ├── development.json
│   ├── environment.json
│   ├── production.json
│   └── routes.js
├── index.js
├── package.json
└── test
    └── app



Submit all bugs here



Join the google group here

IRC? Hang out with us at #papl


Copyright and license

Copyright 2012

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

pineapple copyright 2012 -