Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe
Last active October 27, 2021 04:28
Show Gist options
  • Save drmikecrowe/4bf0938ea73bf704790f to your computer and use it in GitHub Desktop.
Save drmikecrowe/4bf0938ea73bf704790f to your computer and use it in GitHub Desktop.
Sharing constants between node.js app and web app
//** In web app **//
var current = constants.STATE_WAITING;
'use strict';
/* jshint ignore:start */
(function(window){
var constants = {
STATE_COLD : 'STATE_COLD',
STATE_WAITING : 'STATE_WAITING',
STATE_GET_ALL : 'STATE_GET_ALL',
STATE_MAINTENANCE : 'STATE_MAINTENANCE',
};
if ( typeof module === 'object' && module && typeof module.exports === 'object' ) {
module.exports = constants;
} else {
window.constants = constants;
}
})( this );
/* jshint ignore:end */
//** In node.js app **//
var constants = require('../public/js/constants');
var all_states = [constants.STATE_COLD, constants.STATE_GET_ALL, constants.STATE_MAINTENANCE, constants.STATE_WAITING];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment