This article will describe you a fundamental basics of redux in a simple node.js app
npm install redux
redux-demo.js
const redux = require("redux"); const counterReducer = (state = {counter: 0}, action) => { if (action.type === "increment") { return { counter: state.counter + 1, } } else if (action.type === "decrement") { return { counter: state.counter - 1, } } return state; }; const counterSubscriber = () => { const newState = store.getState(); console.log(newState); }; const store = redux.createStore(counterReducer); // in real world this will be subscribed in ui store.subscribe(counterSubscriber); // in real world this will be called from ui store.dispatch({type: "increment"}); store.dispatch({type: "decrement"}); store.dispatch({type: "increment"});
References
https://redux.js.org/tutorials/fundamentals/part-1-overview