Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
sindresorhus / esm-package.md
Last active May 4, 2024 15:48
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.
@johndevs
johndevs / get-all-files.gql
Last active March 19, 2022 20:54
Github GraphQL - Get all file contents in repository
# Provide $query as a variable.
# The query is the same as you would enter into the search field e.g. "org:johndevs in:name feedreader"
query GetFilesQuery($branch: GitObjectID, $query: String!) {
search(first: 1, type: REPOSITORY, query: $query) {
edges {
node {
... on Repository {
object(expression: "master:", oid: $branch) {
... on Tree {
@balupton
balupton / cors.js
Created September 11, 2012 05:21
Acheiving CORS via a Node HTTP Server
// Create our server
var server;
server = http.createServer(function(req,res){
// Set CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Request-Method', '*');
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
res.setHeader('Access-Control-Allow-Headers', '*');
if ( req.method === 'OPTIONS' ) {
res.writeHead(200);
@fcingolani
fcingolani / wp-cron.sh
Created June 14, 2011 19:02
Bash Script to execute wp-cron.php on a Multisite Wordpress.
#!/bin/sh
db_host="host";
db_user="user";
db_pass="password";
db_name="database";
domains=`mysql --silent --skip-column-names --host $db_host --user $db_user -p$db_pass $db_name --execute "SELECT domain FROM wp_blogs WHERE archived = '0' AND spam = '0' AND deleted = '0';"`;
for domain in $domains; do
the_date=`date`;