Most basic example of authenticating with Github in node.
Clone this gist, change keys inside config.js and then hit npm install && node app.js.
| // 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); |
| // this is the background code... | |
| // listen for our browerAction to be clicked | |
| chrome.browserAction.onClicked.addListener(function (tab) { | |
| // for the current tab, inject the "inject.js" file & execute it | |
| chrome.tabs.executeScript(tab.ib, { | |
| file: 'inject.js' | |
| }); | |
| }); |
| var db = mongoose.connect('mongodb://localhost:27017/DB'); | |
| // In middleware | |
| app.use(function (req, res, next) { | |
| // action after response | |
| var afterResponse = function() { | |
| logger.info({req: req}, "End request"); | |
| // any other clean ups |
| // mylogic.js | |
| var MyLogic = { | |
| _currentAccount: null, | |
| fetchAccountByID: function(id) { | |
| // fetch account from database, use promises to reject/resolve | |
| }, | |
| setCurrentAccount: function(account) { | |
| MyLogic._currentAccount = account; | |
| } |
| // Restify Server CheatSheet. | |
| // More about the API: http://mcavage.me/node-restify/#server-api | |
| // Install restify with npm install restify | |
| // 1.1. Creating a Server. | |
| // http://mcavage.me/node-restify/#Creating-a-Server | |
| var restify = require('restify'); |
| 'use strict'; | |
| //mock for superagent - __mocks__/superagent.js | |
| var mockDelay; | |
| var mockError; | |
| var mockResponse = { | |
| status() { | |
| return 200; | |
| }, |
| <html> | |
| <body bgcolor=000000> | |
| <table boder=0 cellpadding=0 cellspacing=0> | |
| <tr height=3> | |
| <td width=3 bgcolor=888888 rowspan=105></td> | |
| <td bgcolor=888888 colspan=54></td> | |
| <td width=3 bgcolor=888888 rowspan=105></td> | |
| </tr> |
| Promise.all([ | |
| someThingThatReturnsAPromise(), | |
| otherThingThatReturnsAPromise(), | |
| lastThingThatReturnsAPromise() | |
| ]) | |
| .then( results => | |
| { | |
| // this... | |
| const [first, second, third] = results; | |
| // ... instead of |
Commonly, npm modules are source controlled using a single dedicated repo for each module. When forking and patching such an existing npm module, typical approaches are either:
"dependencies": {
"patchedmodule": "git+https://github.com/myuser/patchedmodule.git#mypatch"
}