This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |