Skip to content

Instantly share code, notes, and snippets.

View xujiaao's full-sized avatar

Xujiaao xujiaao

  • Shanghai
View GitHub Profile
@slavafomin
slavafomin / nodejs-custom-es6-errors.md
Last active March 9, 2024 12:03
Custom ES6 errors in Node.js

Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.

I've tried to make it as lean and unobtrusive as possible.

Defining our own base class for errors

errors/AppError.js

@tonymtz
tonymtz / gist:d75101d9bdf764c890ef
Last active December 29, 2023 00:40
Uninstall nodejs from OSX Yosemite
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@ramonfritsch
ramonfritsch / expressjs-rewrite.js
Created November 9, 2016 17:06
URL rewrite on ExpressJS 4.0
....
//This is how you'd do on ExpressJS 3.0
app.get('/my/route1/', function (req, res, next) {
req.url = '/other/route2/';
next('route');
});
app.get('/other/route2/', function (req, res, next) {
res.send('I am other route 2');