Skip to content

Home

JavaScript modules Cheat Sheet

Named exports

export const key = 'this-is-a-secret';
import { key } from 'environment';

Default exports

const environment = {
  key: 'this-is-a-secret',
  port: 8000
};

export default environment;
import environment from 'environment';

const { key, port } = environment;

Default + named

export const envType = 'DEV';

const environment = {
  key: 'this-is-a-secret',
  port: 8000
};

export default environment;
import { envType }, environment from 'environment';

const { key, port } = environment;

Export list

const key = 'this-is-a-secret';
const port = 8000;

export {
  key,
  port
};
import { key, port } from 'environment';

Rename export

const key = 'this-is-a-secret';

export { key as authKey };
import { authKey } from 'environment';

Rename import

export const key = 'this-is-a-secret';
import { key as authKey } from 'environment';

Import all

export const envType = 'DEV';

const environment = {
  key: 'this-is-a-secret',
  port: 8000
};

export default environment;
import * as env from 'environment';

const { default: { key, port}, envType } = environment;

More like this

Start typing a keyphrase to see matching snippets.