express and mongoose basic use, as well as to solve cross-domain cors

// Express use 
const = Express the require ( 'Express' ) 
const App = Express () 

app.listen ( 3001, () => { 
    the console.log ( "HTTP: // localhost: 3001" ) 
}) 

app.use ( express.json ()) 

app.get ( '/', (REQ, RES) => { 
    the console.log ( "Hello Express!" ) 
}) 

// CORS 
app.use (the require ( 'CORS') ())   // middleware cors introduced and used to solve the problem of cross-domain 

// Mongoose use 
const = Mongoose the require ( 'Mongoose' ) 
mongoose.connect ( 'MongoDB: //127.0.0.1: 27017 / db_name',{ // db_name name can easily play
    useNewUrlParser: true
})
const model = new mongoose.Schema({
    title: { type: String },
    body: { type: String }
})
const Model = mongoose.model('Model', model)

 After the node test.js

Guess you like

Origin www.cnblogs.com/gehaoyu/p/11922468.html