Skip to content

Commit 0dc7751

Browse files
committed
MERN stack CRUD added
1 parent fe34842 commit 0dc7751

File tree

1,270 files changed

+276834
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,270 files changed

+276834
-99
lines changed

nodejs/database/db.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
SETTING UP MongoDB DATABASE
3+
- create a directory called database
4+
- create db.js inside database directory
5+
- setting up the database server as below
6+
*/
7+
module.exports = {
8+
// change the host name when deploying
9+
db: 'mongodb://0.0.0.0:27017/sagedb'
10+
}
11+
12+
// in this you have defined the MongoDB database and named it
13+
// sagedb
14+
// CONFIGURE SERVER IN THE ROOT DIRECTORY
15+
// - server.js
16+
17+
/* CREATE NEW DIRECTORY name it as models
18+
- create a new model file: Applicant.js
19+
20+
*/

nodejs/models/Applicant.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
DEFINE Mongoose SCHEMA:
3+
- create the schema for interacting with MongoDB schema
4+
- models directory contains schema related files
5+
INSTALL:
6+
- npm install body-parser cors mongoose
7+
- npm i -D nodemon
8+
9+
- you can also install nodemon as dev to
10+
automate the server restarting process
11+
while modifying the server code
12+
13+
*/
14+
// import mongoose module
15+
/* Mongoose is an object data modeling(ODM) library for
16+
- MongoDB and Node.js
17+
- it manages relationships between data,provides schema validation,
18+
- and is used to translate between objects in code and
19+
the representation of those objects in MongoDB.
20+
*/
21+
const mongoose = require('mongoose');
22+
/*
23+
A schema is a JSON object that defines the structure
24+
and contents of your data
25+
*/
26+
const Schema = mongoose.Schema;
27+
28+
let applicantSchema = new Schema({
29+
first_name: {
30+
type: String
31+
},
32+
last_name: {
33+
type: String
34+
},
35+
gender: {
36+
type: String
37+
},
38+
email: {
39+
type: String,
40+
required: true
41+
},
42+
phone_number: {
43+
type: String
44+
},
45+
date_updated: {
46+
type: Date, default: Date.now
47+
}
48+
},
49+
{
50+
// create collocation
51+
collection: 'applicants'
52+
})
53+
// export the schema
54+
module.exports = mongoose.model('Applicant', applicantSchema)
55+
// CREATE routes
56+
// - create applicant.routes.js

nodejs/node_modules/.bin/nodemon

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs/node_modules/.bin/nodetouch

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs/node_modules/.bin/nopt

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs/node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)