Skip to content

Instantly share code, notes, and snippets.

View xuyanbo03's full-sized avatar
🎯
Focusing

Awebone xuyanbo03

🎯
Focusing
View GitHub Profile
@xuyanbo03
xuyanbo03 / gist:227a6afe1347a4d9bf34ff2b9e4765cb
Created January 26, 2018 12:56
express and mongoose template
const express=require("express")
const mongoose=require("mongoose")
//连接MongoDB数据库集合
const DB_URL='mongodb://localhost:27017/app'
mongoose.connect(DB_URL)
mongoose.connection.on('connected',function(){
console.log('mongo connect success')
})
//建文档、字段
const User=mongoose.model('user',new mongoose.Schema({
//app.js
var PORT=3000;
var http=require('http');
var url=require('url');
var fs=require('fs');
var path=require('path');
var mime=require('./mime').types;
var config=require('./config');
var server=http.createServer(function(request,response){
//Service Worker实现离线应用
//app.js
if(navigator.serviceWorker){
navigator.serviceWorker.register('sw.js',{
scope:'/'
}).then(function(reg){
console.log(reg);
}).catch(function(e){
console.log(e);
})
function openDB(name,callback){
var request=window.indexedDB.open(name);
request.onsuccess=function(e){
myDB.db=e.target.result;
callback();
}
request.onupgradeneeded=function(e){
var store =e.target.result.createObjectStore('books',{
keyPath:'isbn'
});
@xuyanbo03
xuyanbo03 / 0_reuse_code.js
Created July 5, 2017 15:53
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console