Skip to content

Commit 18f3006

Browse files
committed
demo node project
1 parent 39c937b commit 18f3006

File tree

6 files changed

+3619
-0
lines changed

6 files changed

+3619
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
/node_modules

contact.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const mongoose=require('mongoose')
2+
3+
const CotectSchema=new mongoose.Schema({
4+
name:{
5+
type:String,
6+
require:true
7+
},
8+
phone:{
9+
type:String,
10+
require:true
11+
}
12+
})

first.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const exp=require('express') // Exp is the name randum only
2+
const port=800;
3+
const db = require('./mong');
4+
const app=exp();
5+
6+
app.get('/',(req,res)=>{
7+
// console.log(req);
8+
res.send("<h1 style='color:red; background-color:yellow;text-align:center'>Hye. ! I am Express ;)</h1>")
9+
10+
})
11+
12+
13+
app.listen(port,(err)=>{
14+
if(err){
15+
console.log("Error..! :(",err);
16+
}
17+
18+
console.log("Express : I am running at port number :", port )
19+
20+
})

mong.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//require the library
2+
const mongoose = require('mongoose');
3+
4+
//connect to the database
5+
mongoose.connect('mongodb://127.0.0.1/contact_list_db');
6+
7+
//acquire the connection(to check if it's successful)
8+
const db = mongoose.connection;
9+
10+
//error
11+
db.on('error', function(err) { console.log(err.message); });
12+
13+
//up and running then print the message
14+
db.once('open', function() {
15+
16+
console.log("Successfully connected to the database");
17+
18+
});

0 commit comments

Comments
 (0)