GithubHelp home page GithubHelp logo

mitchellporter / node-articles-nlp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from heroku-examples/node-articles-nlp

0.0 0.0 0.0 87 KB

Production-ready, scaling-ready Node + Express on Heroku with a message broker (amqp) and state (mongo).

JavaScript 82.80% HTML 5.05% CSS 8.03% Shell 4.12%

node-articles-nlp's Introduction

Node-Articles-NLP

Running Node all the way from development to production on Heroku.

Check it out at http://node-articles-nlp.herokuapp.com/.

Deploy

Local dependencies

Installing

$ brew install mongodb rabbitmq
$ brew services start mongodb
$ brew services start rabbitmq
$ npm install

Running

  1. npm start
  2. http://localhost:5000

Deploying

Deploying is easy - just use the Heroku Button:

Deploy

If you'd rather clone locally and then deploy through the CLI, you can do that too:

git clone [email protected]:heroku-examples/node-articles-nlp.git
cd node-articles-nlp

heroku create

heroku addons:add mongohq
heroku addons:add cloudamqp

heroku config:set NODE_ENV=production
heroku config:set VIEW_CACHE=true
heroku config:set THRIFTY=true

git push heroku master
heroku open

Config

Environment variables are mapped to a config object in lib/config.js. This provides reasonable defaults as well as a layer of generalization (process.env.MONGOHQ_URL => config.mongo_url).

You can locally override the defaults by adding variables to a .env file.

Scaling

The app is separated into two tiers:

This enables horizontally scaling both web traffic and long-running jobs.

On Heroku

The default deploy configuration includes THRIFTY=true, which starts the app in single-dyno mode to avoid charges. With THRIFTY=true, the web process handles both http requests and queued jobs. Keep in mind that this is a specific setting for this app, as THRIFTY is not a standard Heroku configuration.

Of course, a production app should never run in a single instance or make users wait for worker processes. When you're ready to test in staging or deploy to production, you can scale beyond single-dyno mode:

heroku config:unset THRIFTY
heroku ps:scale web=2 worker=2

Locally

npm start runs node-foreman, which will check the Procfile and start a single web process and a single worker process.

To test that your app behaves correctly when clustered in multiple processes, you can specify process scales to node-forman and set CONCURRENCY=4 in a local .env file.

Architecture

Writing maintainable Node apps is all about separating concerns into small, well-defined modules. This barebones app has three distinct components with their own responsibilities:

App

The business logic is all in lib/app. This module orchestrates and provides a facade for the underlying MongoDB database and the RabbitMQ job queue.

Web

The user-facing portion of the project lies in lib/web. This module is responsible for providing an http interface and routing requests. It shows things and relies on an App instance to do things.

Worker

The background processes run through lib/worker. This module is tiny - it just instantiates an App instance to process the job queue.

node-articles-nlp's People

Contributors

fmoliveira avatar hunterloftis 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.