Skip to content

Instantly share code, notes, and snippets.

View artemis15's full-sized avatar
Technology Over a Cup of Coffee

Akash Rajput artemis15

Technology Over a Cup of Coffee
View GitHub Profile
@artemis15
artemis15 / blocking_io_operation.js
Created August 13, 2019 10:42
Example of Blocking I/O operation
const _fs= require('fs');
let _contents = _fs.readFileSync('package.json').toString();
console.log(_contents);
@artemis15
artemis15 / Non_blocking_io.js
Created August 13, 2019 10:48
Example of Non-blocking I/O operation
const _fs = require('fs');
_fs.readFile('package.json', function (_err, _buf){
console.log(_buf.toString());
});
@artemis15
artemis15 / Sample_server_node.js
Created August 13, 2019 11:12
Sample Node.js Server
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200);
res.end('Hurray! you have caught your 1st pokemon');
});
server.listen(3020, ()=>{
console.log('the server is running on http://localhost:3020');
});
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'content-type':'text/html'});
res.end('<p><strong>Hurray!</strong> you have caught your 1st pokemon.</p>');
});
server.listen(3020, ()=>{
console.log('the server is running on http://localhost:3020');
});
@artemis15
artemis15 / server.js
Created August 29, 2019 16:09
Firing_up_express_js
const express = require('express'),
app = express();
app.get('/',(request,response)=>{
response.send('Go-catcha Express!');
});
app.listen(3020,()=>console.log('node.js express server started at port 3020'));
@artemis15
artemis15 / server.js
Created September 9, 2019 02:49
Simple Server js file with HBS template in Express framework
const app = require('express')();
const path = require('path');
//setting our app engine to handlebars
app.set('views', path.join(__dirname,'views'))
app.set('view engine', 'hbs');
app.get('/',(request,response)=>{
response.render('index');
});
@artemis15
artemis15 / index.hbs
Created September 9, 2019 02:51
Index template file for HBS Express
<!-- index.hbs file -->
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>{{title}}</title>
</head>
<body>
<p>Go-catcha Express!! (coming from index file)</p>
@artemis15
artemis15 / server.js
Created September 9, 2019 03:04
Server js file with pokemon list
const app = require('express')();
const path = require('path');
//setting our app engine to handlebars
app.set('views', path.join(__dirname,'views'));
app.set('view engine', 'hbs');
app.get('/',(request,response)=>{
let _pokemonList = getRandomPokemonList();
response.render('index',{pokemon:_pokemonList});
@artemis15
artemis15 / index.hbs
Created September 9, 2019 03:06
Index template to receive data from serverjs
<!-- index.hbs file -->
<!DOCTYPE html>
<html>
<body>
<ul>
{{#each pokemon}}
<li>
{{this}}
</li>