Last active
October 27, 2021 04:28
-
-
Save drmikecrowe/4bf0938ea73bf704790f to your computer and use it in GitHub Desktop.
Sharing constants between node.js app and web app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//** In web app **// | |
var current = constants.STATE_WAITING; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//** 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