This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'), | |
app = express(); | |
//Different routes | |
app.get('/users/john',(request,response)=>{ | |
response.send(`John’s page`); | |
}); | |
app.get('/users/mark',(request,response)=>{ | |
response.send(`John’s page`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'), | |
app = express(); | |
//requiring the basic_router.js | |
app.use('/users',require('.react-router/basic_router')); | |
//routes | |
app.get('/posts/newpost',(request,response)=>{ | |
response.send('new post'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'), | |
router = express.Router(); | |
//making use of normal routes | |
router.get('/john',(request,response)=>{ | |
response.send('Home of user'); | |
}); | |
router.get('/mark',(request,response)=>{ | |
response.send('Home of user'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'), | |
router = express.Router(); | |
router.get('/',(request,response)=>{ | |
response.send('Home of user'); | |
}); | |
//some other endpoints to submit data | |
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'), | |
app = express(); | |
app.use('/users',require('./basic_router')); | |
app.use('/api',require('./api_route')); | |
app.get('/posts/newpost',(request,response)=>{ | |
response.send('new post'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'), | |
hbs = require('express-handlebars').create({defaultLayout:'main.hbs'}), | |
app = express(); | |
app.engine('hbs', hbs.engine); | |
app.set('view engine','hbs'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'), | |
hbs = require('express-handlebars').create({defaultLayout:'main.hbs'}), | |
app = express(); | |
//setting our app engine to handlebars | |
app.engine('hbs', hbs.engine); | |
app.set('view engine', 'hbs'); | |
app.get('/',(request,response)=>{ | |
response.render('home',{title: 'Home'}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'), | |
app = express(); | |
//setting the port | |
app.set(‘port’, process.env.PORT || 3000); | |
//first middleware | |
app.use((request,respone,next)=>{ | |
console.log(`processing for data for ${request.url}`); | |
next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//server.js file | |
const express = require('express'), | |
app = express(); | |
//setting the port | |
app.set('port', process.env.PORT || 3000); | |
// | |
app.get('/',(request,response)=>{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//server.js | |
const express = require('express'), | |
app = express(), | |
//You must require the body-parser middleware to access request.body in express | |
bodyParser = require('body-parser'); | |
//configuring bodyparser | |
app.use(bodyParser.json()); |