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'), | |
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'), | |
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'), | |
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'), | |
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
//filewatcher.js | |
const net = require('net'), | |
fs = require('fs'), | |
filename = process.argv[2], | |
server = net.createServer((connection)=>{ | |
console.log('Subscriber connected'); | |
connection.write(`watching ${filename} for changes`); | |
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
//index.html | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Home page</title> | |
</head> | |
<body> | |
<button>Get data</button> |
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'), | |
server = express(), | |
users = require('./users'); | |
//setting the port. | |
server.set('port', process.env.PORT || 3000); | |
//Adding routes | |
server.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
//users.js | |
module.exports.users = [ | |
{ | |
name: 'Mark', | |
age : 19, | |
occupation: 'Lawyer', | |
married : true, | |
children : ['John','Edson','ruby'] | |
}, | |
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'), | |
server = express(); | |
server.set('port', process.env.PORT || 3000); | |
//Basic routes | |
server.get('/', (request,response)=>{ | |
response.send('Home page'); | |
}); |