|
| 1 | +# RediSolar for Node.js |
| 2 | + |
| 3 | +# Introduction |
| 4 | + |
| 5 | +This is the sample application codebase for RU102JS, Redis for JavaScript developers. |
| 6 | + |
| 7 | +# Prerequisites |
| 8 | + |
| 9 | +In order to start and run this application, you will need: |
| 10 | + |
| 11 | +* [Node.js](https://nodejs.org/en/download/) (8.9.4 or newer, we recommend using the current Long Term Stable version) |
| 12 | +* npm (installed with Node.js) |
| 13 | +* Access to a local or remote installation of [Redis](https://redis.io/download) version 5 or newer (local preferred) |
| 14 | + |
| 15 | +# Setup |
| 16 | + |
| 17 | +To get started: |
| 18 | + |
| 19 | +``` |
| 20 | +$ npm install |
| 21 | +``` |
| 22 | + |
| 23 | +# Configuration |
| 24 | + |
| 25 | +The application uses a configuration file, `config.json` to specify the port that it listens |
| 26 | +on plus some logging parameters and how it connects to a database. |
| 27 | + |
| 28 | +The supplied `config.json` file is already set up to use Redis on localhost port 6379. Change these values if your Redis instance is on another host or port. |
| 29 | + |
| 30 | +``` |
| 31 | +{ |
| 32 | + "application": { |
| 33 | + "port": 8081, |
| 34 | + "logLevel": "debug", |
| 35 | + "dataStore": "redis" |
| 36 | + }, |
| 37 | + "dataStores": { |
| 38 | + "redis": { |
| 39 | + "host": "localhost", |
| 40 | + "port": 6379, |
| 41 | + "keyPrefix": "ru102js" |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +The `keyPrefix` for Redis is used to namespace all the keys that the application generates or |
| 48 | +references. So for example a key `sites:999` would be `ru102js:sites:999` when written to Redis. |
| 49 | + |
| 50 | +# Load Sample Data |
| 51 | + |
| 52 | +To load sample site data and sample metrics, run: |
| 53 | + |
| 54 | +``` |
| 55 | +npm run load src/resources/data/sites.json flushdb |
| 56 | +``` |
| 57 | + |
| 58 | +`flushdb` is optional, and will erase ALL data from Redis before inserting the sample data. |
| 59 | + |
| 60 | +The application uses the key prefix `ru102js` by default, so you should be able to use the |
| 61 | +same Redis instance for this application and other data if necessary. |
| 62 | + |
| 63 | +# Development Workflow |
| 64 | + |
| 65 | +In order to speed up development, you can run the application using `nodemon`, so that any |
| 66 | +changes to source code files cause the server to reload and start using your changes. |
| 67 | + |
| 68 | +``` |
| 69 | +npm run dev |
| 70 | +``` |
| 71 | + |
| 72 | +Edit code, application will hot reload on save. |
| 73 | + |
| 74 | +If you want to run without `nodemon`, use: |
| 75 | + |
| 76 | +``` |
| 77 | +npm start |
| 78 | +``` |
| 79 | + |
| 80 | +But you will then need to stop the server and restart it when you change code. |
| 81 | + |
| 82 | +# Accessing the Front End Web Application |
| 83 | + |
| 84 | +You should be able to see the front end solar dashboard app at: |
| 85 | + |
| 86 | +``` |
| 87 | +http://localhost:8081/ |
| 88 | +``` |
| 89 | + |
| 90 | +# Running Tests |
| 91 | + |
| 92 | +The project is setup to use [Jest](https://jestjs.io/en/) for testing. To run all tests: |
| 93 | + |
| 94 | +``` |
| 95 | +npm test |
| 96 | +``` |
| 97 | + |
| 98 | +To run a specific suite of tests (e.g. those in `tests/basic.test.js`): |
| 99 | + |
| 100 | +``` |
| 101 | +npm test -t basic |
| 102 | +``` |
| 103 | + |
| 104 | +To run Jest continuously in watch mode, which gives you access to menus allowing you to run |
| 105 | +subsets of tests and many more options: |
| 106 | + |
| 107 | +``` |
| 108 | +npm testdev |
| 109 | +``` |
| 110 | + |
| 111 | +# Linting |
| 112 | + |
| 113 | +This project uses [ESLint](https://eslint.org/) with a slightly modified version of the |
| 114 | +[Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript). |
| 115 | + |
| 116 | +* The file `.eslintrc` contains a short list of rules that have been disabled for this project. |
| 117 | +* The file `.eslintignore` contains details of paths that the linter will not consider when |
| 118 | +linting the project. |
| 119 | + |
| 120 | +To run the linter: |
| 121 | + |
| 122 | +``` |
| 123 | +npm run lint |
| 124 | +``` |
0 commit comments