GithubHelp home page GithubHelp logo

holmusk's Introduction

holmusk

This README documents whatever steps are necessary to get the application up and running.

Local Development Environment setup

In your local.js file, you'll need to define an additional connections settings. Below is an example:

/backend/config/local.js

{
  connections: {
    postgres: {
      adapter: 'sails-postgresql',
      host: 'localhost',
      port: 5432,
      user: '<your username>',
      password: '<your password>',
      database: 'holmusk'
    }
  },
  elasticsearch: {
    host: 'localhost:9200',
    log: 'trace'
  }
};

Production settings are specified through environment variables.

Getting Started

Have Node.js installed.

Fork this project, and do a git clone from your fork. The project directory should look as follows (some details omitted):

|-- scraper/
		|-- lib/
		|-- test/
		|-- index.js
    |-- package.json
|-- backend/
		|-- api/
			 |-- controllers/
			 |-- models/
       |-- responses/
       |-- services/
		|-- config/
    |-- test/
    |-- app.js
    |-- package.json
|-- README.md

First, set up the API component:

cd backend
npm install
sails lift

Start scraping:

cd scraper
npm install
node index.js {number of pages to scrape} {brand}

You can call node index.js without arguments to use the default 1, 'generic' parameters. Each page contains 20 food items.

At this point, the food objects will have been saved into the database.

API Routes

API Endpoint Description
GET /api/v1/foods/autocomplete?q=:term Search Foods by :term
GET /api/v1/foods Get all Foods
GET /api/v1/foods/:id Find a single Food of a given :id
POST /api/v1/foods Create a new Food

For convenient testing, use Postman and import this Postman collection. Postman is a desktop API testing tool.

API HTTP Status Codes

Status Code Meaning
200 OK Generic successful execution.
201 Created Used as a response to POST method execution to indicate successful creation of a resource.
400 Bad Request Your request could not be understood by the server. This may be due to the data payload is not in the expected format.
401 Unauthorized The request requires authentication and none was provided.
403 Forbidden Request failed because you do not have authorization to access a specific resource.
404 Not Found The specified object could not be found.
500 Internal Server Error We had a problem with our server. Report the issue or try again later.

Running Tests

Developers are strongly encouraged to write unit tests for new code, and to submit new unit tests for old code. To run unit/integration tests, run:

npm test

Both the scraper and backend components are covered by tests.

Code Style Enforcement with JSCS

For a software team to be sure everyone follows consistent code style and conventions, it's important to have an automated linters to enforce best practices. To do this, we're using the JSCS linter. This project enforces the Google Javascript Style Guide.

If you're developing this project, you must have this installed. Plugins are available on all major code editors. In a real team setting, you can also define a git post-commit hook that runs a jscs grunt task to enforce all committers to strictly follow the style guide.

Deployment

To deploy (i.e. on Heroku), you'll need to ensure that the following environment variables are defined (see config/env/production.js and config/elasticsearch.js):

  • PG_HOSTNAME
  • PG_PORT
  • PG_USER
  • PG_PASSWORD
  • PG_DATABASE
  • ES_HOST
  • ES_LOG

If you are on local development, make sure your local.js file contains the above variables.

Credits

Contributors:

Trello board

holmusk's People

Contributors

yosriady avatar

Watchers

James Cloos 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.