Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe drmikecrowe/app.js
Last active Sep 25, 2017

Embed
What would you like to do?
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];
@mathiesha

This comment has been minimized.

Copy link

mathiesha commented Oct 21, 2016

Thanks for this handy snippet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.