Friday, April 24, 2020

Making Circle from Square in Python using turtle module

import turtle

my_turtle = turtle.Turtle()

def square(length, angle):
    for i in range(4):       
        my_turtle.forward(length)
        my_turtle.right(angle)

for i in range(50):
    my_turtle.right(10)
    square(100,90)


Thursday, March 26, 2020

Visit Count Session in Node and Express

        if(!request.session.visitcount){
            request.session.visitcount = 0;
        }
        request.session.visitcount += 1
        console.log(`Number of visits: ${request.session.visitcount}`)

Sunday, March 22, 2020

Node JS Tricks


  • If Cannot install thirdparty application via terminal, you will need package.json file for that.

To install package.json file, write this in your terminal

npm init

  • For automated loading of console in visual code or other text editor, you need to install nodemon. For that, you need to install globally with keyword -g
npm install -g nodemon 


  • To access in console bar with nodemon, write this in terminal
    nodemon .\demo.js
  • If  You see the error while running nodemon, Visual studio code cmd error: Cannot be loaded because running scripts is disabled on this system, follow this link

Simple Test and Async Test with Jasmine

npm install --save-dev jasmine

./node_modules/.bin/jasmine init

npm install --save-dev request

Sunday, March 15, 2020

Get Local IP In node.js

'use strict';

var os = require('os');
var ifaces = os.networkInterfaces();

Object.keys(ifaces).forEach(function (ifname) {
  var alias = 0;

  ifaces[ifname].forEach(function (iface) {
    if ('IPv4' !== iface.family || iface.internal !== false) {
      // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
      return;
    }

    if (alias >= 1) {
      // this single interface has multiple ipv4 addresses
      console.log(ifname + ':' + alias, iface.address);
    } else {
      // this interface has only one ipv4 adress
      console.log(ifname, iface.address);
    }
    ++alias;
  });
});

// en0 192.168.1.101
// eth0 10.0.0.101

Monday, February 24, 2020

How To Connect Request Post on Node.js Localhost?

Index.js
/*
 *Primary file for the API
 *
 */
 // Dependencies
 const http = require('http');

 const server = http.createServer((req, res) =>{
  if (req.url === '/'){
  res.write('Hello World');
  res.end();
  }
 });

 //The server should respond to all requests with a string
server.listen(3000);

console.log('Listening on port 3000');

Then run on CMD Terminal

node index.js