/webjobs.node

A small node site

Primary LanguageJavaScriptISC LicenseISC

webjobs.node

A small node site

This site allows the user to request web URLs in a browser form and see the results of their requests. Updates appear automatically (no refresh needed) as long as the browser websocket is connected. The results can be viewed on a details page.

This is a sample work project for a job application. I solved the problem using a combination of technologies:

  • Node.js express server
  • Websockets for two-way browser <-> server communication
  • Redis Pub/Sub for event queue
  • Redis database for data storage
  • Promise-based architecture built on Bluebird

Data Model

Job represents the user's request and stores the URL, status, and result. Errors are also stored in the result. Queue manages jobs and creates workers to work them. Worker performs the request and saves the result.

Installation

Assuming you have node/npm installed, simply clone this repository. To start the server:

npm install
npm start

Configuration

Default webserver port is 8000, websocket is 8111. You can change these by setting PORT and WS_PORT environment variables, respectively. When changing WS_PORT, it is necessary to also update the bundled react script with browserify. For example, if you want to run on 8123 and 8124, you would run:

browserify -t [envify --WS_PORT 8124] -t [babelify] app/app.js -o app/public/bundle.js
PORT=8123 WS_PORT=8124 npm start