lanhsotret / beginner-CSS-and-Javascript

0 stars 1 forks source link

kết nối database cũng dễ #3

Open HoAnhTungPrimelabo opened 4 years ago

HoAnhTungPrimelabo commented 4 years ago
var express = require('express'); 
var app = express();
var mongodb = require('mongodb');
var fs = require('fs');
const util = require("util");
// app.set('view engine', 'ejs');
// app.get('/', function(req, res){ 
//      res.render('index',{user: "Great User",title:"homepage"});
// });
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
    fs.writeFile(
            "foo.txt", // file
            "bar", // string
            {
                encoding: "utf8",
                flag: "a" // flag that specifies that it will append stuff
            },
            function(){ console.log("done!") }
    )
    mongoCl = mongodb.MongoClient;
    var url = 'mongodb://localhost:27017';
    mongoCl.connect(url, function (err, client){
        if(err) {
            console.log('error', err);
        } else {
            var db = client.db('quanlyhs');
            console.log('ok');
            var collection = db.collection('lop');
            collection.find({userId:1}).toArray(function(err, result) {
                    var d = {tung1: 'aaa', tung2: 'bbb'};
                    res.render('tung', {tung1: 'xin chào', data: result});
            });
        }
    });
})

app.listen(8080);
lanhsotret commented 4 years ago

không hiều....@@...

Vào Th 6, 27 thg 12, 2019 vào lúc 11:03 HoAnhTungPrimelabo < notifications@github.com> đã viết:

Reopened #3 https://github.com/lanhsotret/beginner-CSS-and-Javascript/issues/3.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lanhsotret/beginner-CSS-and-Javascript/issues/3?email_source=notifications&email_token=AN7NNXQLO3V3W36ZHBXDM2DQ2V47ZA5CNFSM4J7U45X2YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOVVZUYNY#event-2910014519, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN7NNXVOAIIHGDWNK4UAIK3Q2V47ZANCNFSM4J7U45XQ .

lanhsotret commented 4 years ago

theo hướng dẫn nó có schema, collection nữa.... mà mongoCl = mongodb.MongoClient; là cái gì...

Vào Th 2, 30 thg 12, 2019 vào lúc 19:07 Trương Văn Hồ lanhcupi@gmail.com đã viết:

không hiều....@@...

Vào Th 6, 27 thg 12, 2019 vào lúc 11:03 HoAnhTungPrimelabo < notifications@github.com> đã viết:

Reopened #3 https://github.com/lanhsotret/beginner-CSS-and-Javascript/issues/3.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lanhsotret/beginner-CSS-and-Javascript/issues/3?email_source=notifications&email_token=AN7NNXQLO3V3W36ZHBXDM2DQ2V47ZA5CNFSM4J7U45X2YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOVVZUYNY#event-2910014519, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN7NNXVOAIIHGDWNK4UAIK3Q2V47ZANCNFSM4J7U45XQ .

lanhsotret commented 4 years ago

app.get('/', (req, res) => {

fs.writeFile(

        "foo.txt", // file

        "bar", // string

        {

            encoding: "utf8",

            flag: "a" // flag that specifies that it will append stuff

        },

        function(){ console.log("done!") }

cái này là viết bar vào file foo.txt mà... có tác dụng gì vậy...

Vào Th 2, 30 thg 12, 2019 vào lúc 19:12 Trương Văn Hồ lanhcupi@gmail.com đã viết:

theo hướng dẫn nó có schema, collection nữa.... mà mongoCl = mongodb.MongoClient; là cái gì...

Vào Th 2, 30 thg 12, 2019 vào lúc 19:07 Trương Văn Hồ < lanhcupi@gmail.com> đã viết:

không hiều....@@...

Vào Th 6, 27 thg 12, 2019 vào lúc 11:03 HoAnhTungPrimelabo < notifications@github.com> đã viết:

Reopened #3 https://github.com/lanhsotret/beginner-CSS-and-Javascript/issues/3.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lanhsotret/beginner-CSS-and-Javascript/issues/3?email_source=notifications&email_token=AN7NNXQLO3V3W36ZHBXDM2DQ2V47ZA5CNFSM4J7U45X2YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOVVZUYNY#event-2910014519, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN7NNXVOAIIHGDWNK4UAIK3Q2V47ZANCNFSM4J7U45XQ .