I initially built Jobuddy using the php framework Laravel.
I decided that it's high time i take a new turn. Nodejs
was best suited for the goal i was trying to achieve.
SETTING UP THE SERVER
We will start by creating a new folder, we are going to call
this folder the backend.Inside this folder we are going to
create a new text file and name it app.js. Inside the app.js
we are going to place these following lines of code.
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const cors = require('cors');
const errorHandler = require('errorhandler');
const mongoose = require('mongoose');
mongoose.promise = global.Promise;
const isProduction = process.env.NODE_ENV === 'production';
const app = express();
app.use(cors());
app.use(require('morgan')('dev'));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({ secret: 'LightBlog', cookie: { maxAge: 60000 }, resave: false, saveUninitialized: false }));
if(!isProduction) {
app.use(errorHandler());
}
mongoose.connect('mongodb://localhost/lightblog');
mongoose.set('debug', true);
// Add your models in this place
// Add your routes in this place
app.use(require('./routes'));
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
if (!isProduction) {
app.use((err, req, res) => {
res.status(err.status || 500);
res.json({
errors: {
message: err.message,
error: err,
},
});
});
}
app.use((err, req, res) => {
res.status(err.status || 500);
res.json({
errors: {
message: err.message,
error: {},
},
});
});
const server = app.listen(8000, () => console.log('Server started on http://localhost:8000'));
After we are done with the code, the next step we are going to take is
installing some pretty important packages.We can do this by navigating
to the backend folder using the command line or terminal then we run
this command
npm i -S path express body-parser express-session cors errorhandler mongoose morgan
After the packages have been successfully installed we will then need
to install nodemon to automatically reload our app for everything time
we make a new change.To achieve this we are going to use this command in
the backend folder.
npm install --g nodemon
After we do that we run nodemon app.js to reload our app
CREATING THE MODELS FOR OUR APP.
The first thing we have to do is creating our Jobpost model which we will be using
to post jobs and it is going to have a nameofcompany, jobtitle, jobrequirements,pastexperience,
skills,educationlevel,salaryrange,companylocation, companyemailaddress and a timestamp. After doing this
you then create a new folder inside the backend folder and name it models. This is the folder
were we are going to be putting our models. Inside the models folder we will create a file
and name it as Jobpost.js Inside the post.js we will post the following code
const mongoose = require('mongoose');
const { Schema } = mongoose;
const PostjobSchema = new Schema({
nameofcompany: String,
jobtitle: String,
jobrequirements: String,
pastexperience: String,
skills: String,
educationlevel: String,
salaryrange: String,
companylocation: String,
companyemailaddress: String
}, { timestamps: true });
PostjobSchema.methods.toJSON = function() {
return {
_id: this._id,
nameofcompany: this.nameofcompany,
jobtitle: this.jobtitle,
jobrequirements: this.jobreqiurements,
pastexperience: this.pastexperience,
skills:this.skills,
educationlevel:this.educationlevel,
salaryrange: this.salaryrange,
companylocation:this.companyrange,
companyemailaddress:this.companyemailaddress,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
};
};
mongoose.model('Postjob', PostjobSchema);
In the part two of this series we are going to dive right into routing.
Thank you so much for sharing this amazing post with us!
Have you heard about Partiko? It’s a really convenient mobile app for Steem! With Partiko, you can easily see what’s going on in the Steem community, make posts and comments (no beneficiary cut forever!), and always stayed connected with your followers via push notification!
Partiko also rewards you with Partiko Points (3000 Partiko Point bonus when you first use it!), and Partiko Points can be converted into Steem tokens. You can earn Partiko Points easily by making posts and comments using Partiko.
We also noticed that your Steem Power is low. We will be very happy to delegate 15 Steem Power to you once you have made a post using Partiko! With more Steem Power, you can make more posts and comments, and earn more rewards!
If that all sounds interesting, you can:
Thank you so much for reading this message!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @floxygara! You received a personal award!
Happy Birthday! - You are on the Steem blockchain for 1 year!
Click here to view your Board
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @floxygara! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit