Giter Club home page Giter Club logo

ffs's Introduction

Usage

  1. Install dependencies by running npm install in the project folder.
  2. Start a Mongodb server. The project includes the shortcut npm run-script db.
  3. Start the server by running npm start.

Development

Folders

  1. tests: Independent test suite for the REST API. It can be run by opening a terminal in that folder, installing the project with npm install and then running the tests with npm start. Once the project is installed you can run the tests directly from root folder with make test.
  2. node_modules: Any dependency automatically resolved with npm install will be placed here. Please, do not add any file here, this folder should be modified just by npm. This folder should be excluded from the Git repository as it can be create automatically by running npm install.
  3. docs: Independent project where is located the REST API documentation. To browse the documentation just open the directory in a terminal window, instal the project with npm install and then run it with npm start. The log will show you the URL where you can browse the documentation.
  4. model: This folder contains the declaration of the model, using Mongoose ODM. File model.js will load automatically any other *.js file in the folder and initialize a class for that model.
  5. controller: This folder contains the declaration of the controller. File controller.js will load automatically any other `.js file in the folder and hook it to the controller module.
  6. vendor: Small utilities like regular expressions to verify emails or helpers to print messages in the log with fancy colors.

Adding a new model

  1. Check out Mongoose documentation.
  2. Create a file myclass.js in folder models. That file will be automatically loaded so you will able to instantiate an object of your newly created class in app.js with just a line like this: var my_instance = new Myclass();
  3. Check out Mongoose documentation for more information about the structure of the model. module.exports will be passed directly to new Schema() to create the class.
  4. If you need to validate a String using a regular expression take a look at vendor/regex.js as you may find there a regular expression to solve you problem. If there is no such regular expression, add it!

Adding a new controller

  1. Check out Express documentation.
  2. Create a file mycontroller in controllers folder if required. The best thing to do is to create just one controller file for each model file, as one controller file can be responsible for more than just one action.
  3. If you have created a new file you'll need to access the model in the controller, so require the model with this line: var model = require( '../models/model.js' );. Remember that NodeJS caches any require, so you are not executing the module but getting access to the previously processed module, that means that this is very fast!
  4. Add a function to handle the use case you want to implement. Remember that this function will have the following signature: function( req, res ), where req is the user's request and res is the server's response. You won't use return here, but will use res.send();.
  5. Choose a descriptive name for you method and make it available by adding it to module.exports.
  6. Modify app.js so when the proper request arrives is your new method the one called, using a line like this: app.get( '/user', controller.User.allUsers );.

ffs's People

Contributors

sumolari avatar ssiro16 avatar

Stargazers

cat avatar

Watchers

 avatar James Cloos avatar Vigmore avatar  avatar cat avatar Javier Rodríguez Vidal avatar

Forkers

cathd

ffs's Issues

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.