Skip to content

Instantly share code, notes, and snippets.

View JustFly1984's full-sized avatar

Alexey Lyakhov JustFly1984

  • Thailand
View GitHub Profile
@bradwright
bradwright / websockets-server.js
Created June 11, 2011 23:29
Pure Node.js WebSockets server
/*
* node-ws - pure Javascript WebSockets server
* Copyright Bradley Wright <[email protected]>
*/
// Use strict compilation rules - we're not animals
'use strict';
var net = require('net'),
crypto = require('crypto');
@acdlite
acdlite / app.js
Last active January 20, 2023 08:23
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@SarasArya
SarasArya / handler.js
Last active May 15, 2021 22:05
Serverless Sentry Error Handler example
// Node version 10.x AWS Lambda Serverless framework
const Sentry = require('@sentry/node'); // sentry version "@sentry/node": "^5.5.0",
Sentry.init({
dsn: 'https://[email protected]/1234567',
async beforeSend(event) {
console.log('\n Caught an exception \n');
return event;
},
@sindresorhus
sindresorhus / esm-package.md
Last active November 17, 2024 22:07
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.