Skip to content

Instantly share code, notes, and snippets.

View chungchi300's full-sized avatar

Jeff Chung chungchi300

View GitHub Profile
@chungchi300
chungchi300 / better-nodejs-require-paths.md
Created February 18, 2018 13:38 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

//very important,these javascript component is more debuggable then native
import fetch from 'isomorphic-fetch';
import FormData from 'form-data';
let formData = new FormData();
formData.append('file',fs.createReadStream('test/api/testMedia.jpg'));
//implement your own header function
let headers = prepareHeaders();
@branneman
branneman / better-nodejs-require-paths.md
Last active December 5, 2025 02:17
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@appastair
appastair / jsonp.js
Last active August 23, 2020 17:52
Cross-domain JSONP Example (jQuery/PHP)
jQuery(function($){
$.ajax({
type: 'GET',
url: '//remote.org/jsonp.php',
data: {
field: 'value'
},
dataType: 'jsonp'
crossDomain: true,
}).done(function(response){