mongodb atlas 회원가입. (free)
collection +
doc +
server.js //추가
var db
const MongoClient = require('mongodb').MongoClient
MongoClient.connect('mongodb+srv://_id_:_password_@cluster0.cpnf3.mongodb.net/myFirstDatabase?retryWrites=true&w=majority', function(error, client){
if (error) return console.log(error)
db = client.db('todoapp')
//db.collection('post').insertOne( {제목:'company',주소:'00회사'} , function(error,result){
// console.log('저장완료');
//});
})
app.get('/write', function(req, res){
res.sendFile(__dirname + '/form.html')
});
app.post('/add', function(req, res){
//console.log(req.body.title);console.log(req.body.title);
db.collection('post').insertOne( {제목:req.body.title, 날짜:req.body.date} , function(error,result){
console.log('저장완료');
});
res.send('trans...');
});
app.get('/list', function(req, res){
// db.collection('post').find().toArray(function(error,result){
// console.log(result);
// res.render('list.ejs', { posts: result} );
// });
res.render('list.ejs');
});'NODE' 카테고리의 다른 글
| Node.js + Mysql 연결하기 (0) | 2024.08.08 |
|---|---|
| NODE study 시작 (환경설정) (0) | 2021.07.02 |