Snippets Collections
// create a schema
const eventSchema = new Schema({
  name: String,
  slug: {
    type: String,
    unique: true
  description: String

// create the model
const eventModel = mongoose.model('Event', eventSchema);

// middleware -----
// make sure that the slug is created from the name
eventSchema.pre('save', function(next) {
  this.slug = slugify(;

// function to slugify a name
function slugify(text) {
  return text.toString().toLowerCase()
    .replace(/\s+/g, '-')           // Replace spaces with -
    .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
    .replace(/\-\-+/g, '-')         // Replace multiple - with single -
    .replace(/^-+/, '')             // Trim - from start of text
    .replace(/-+$/, '');            // Trim - from end of text
# There are a few ways to change the url in wordpress

# The prefered method is the wp-cli via search-replace.
$ wp search-replace 'http://example.test' '' --skip-columns=guid

# You can also test with a dry run
$ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run

# If the wp-cli is not available or you can't use SSH there are three other ways to try inside the files wp-config and functions.php

# At the beginning of wp-config.php, add
define( 'WP_HOME', '' );
define( 'WP_SITEURL', '' );

# At the end of the file, before the comment to stop editing here, you can set the relocate method. This always takes the current url calling "/wp-login.php" as slug as site url.

# Inside funcions.php, as first call, you can set
update_option( 'siteurl', 'http://example.test');
update_option( 'home', '');

# As last resort, you can change the database values manually.You will have to look for "siteurl" in the table "wp_options" and change the values to the correct url.

# After changing the url, don't forget to remove the above settings again. Move to your settings in the backend and check the url. Also, inside the options section, look for "permalinks". It will bring you to an options page where you can regenerate the dynamic links. Without this regenerating, links for assets, media files and so an would possibly keep pointing to the old url. 
const urlString =
const urlParameters = new URLSearchParams(urlString)

if (urlParameters.has('parameter')) {
const getURLParameters = url =>
  (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
    (a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a),

// Examples
getURLParameters(''); // {n: 'Adam', s: 'Smith'}
getURLParameters(''); // {}

Mon Jun 14 2021 12:21:17 GMT+0000 (UTC)

#express #nodej #mongodb #mongoose #slug #url

Fri Jun 11 2021 14:15:50 GMT+0000 (UTC),

#wordpress #configuration #url #network

Thu Apr 08 2021 13:13:09 GMT+0000 (UTC)

#javascript #url

Wed Nov 04 2020 08:47:54 GMT+0000 (UTC)

#javascript #http #get #url

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension