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(); | |
//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'), | |
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(); | |
app.get('/',(request,response)=>{ | |
response.send(‘Hello world’); | |
}); | |
//Binding the server to a port(3000) | |
app.listen(3000,()=>console.log(‘express server started at port 300’)); |
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'); | |
}); |
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 http = require('http'), | |
url = require('url'), | |
makeServer = function (request,response){ | |
let path = url.parse(request.url).pathname; | |
console.log(path); | |
if(path === '/'){ | |
response.writeHead(200,{'Content-Type':'text/plain'}); | |
response.write('Hello world'); |