Skip to content

Instantly share code, notes, and snippets.

View svsh227's full-sized avatar

SHUBHAM VERMA svsh227

  • * Capgemini India * Srijan Technologies, Gurugram * Daffodil Software Ltd, Gurgaon
  • Gurugram, India
View GitHub Profile
@svsh227
svsh227 / server.js
Created April 26, 2020 18:39
Show Desktop Notification in Javascript App- Create a Node Server: why we are creating a node server? we have discussed above. Let's create a file "server.js" in the "root" directory and write the below code:
const express = require('express');
const app = express();
const path = require('path');
app.use(express.static(path.join(__dirname, '/')));
app.get('/', function (req, res) {
console.log("__dirname : ",__dirname);
res.sendFile(path.join(__dirname, 'index.html'))
});
@svsh227
svsh227 / index.html
Last active April 26, 2020 19:24
Show Desktop Notification in Javascript App- In this step, we will create a file "index.html" and in this file, we will write out notification logic, and we will write some HTML to show on the web browsers. Make a file index.html and write the below codes:
<html>
<head>
<title>Notification demo by Shubham Verma</title>
<script>
function showDesktopNotification() {
const myNotification = new Notification("heading of the notification", {
icon: 'demo2.jpg',
body: "This is the body of the notification, Its a demo for learnig browser notification",
@svsh227
svsh227 / App.js
Created April 24, 2020 20:47
Use the component in the app: in the App.js file, we will import our component and use it. See the below code:
import React from 'react';
import './App.css';
import TypeAheadDropDown from './TypeAheadDropDown';
import cities from './indianCities.js'
function App() {
return (
<div className="App">
<TypeAheadDropDown iteams={cities} />
</div>
);
@svsh227
svsh227 / TypeAheadDropDown.css
Created April 24, 2020 20:42
Design our TypeAheadDropDown: Let's write some CSS to design our component, create a file "TypeAheadDropDown.css" in "src" folder, and write the below codes:
.TypeAheadDropDown{
width: 100%;
border: 1px solid gray;
box-shadow: 0 0 1px rgba(0,0,0,0.1), 0 2px 4px 1px rgba(0,0,0, .18);
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: rgba(0, 0, 0, 0.73);
}
.TypeAheadDropDown input{
@svsh227
svsh227 / TypeAheadDropDown.js
Created April 24, 2020 20:37
Create a component "TypeAheadDropDown.js": Now it's time to create our component, create a file "TypeAheadDropDown.js" inside "src" folder and write the below code: src/TypeAheadDropDown.js:
// TypeAheadDropDown.js
import './TypeAheadDropDown.css'
import React from 'react';
export default class TypeAheadDropDown extends React.Component {
constructor(props) {
super(props);
this.state = {
suggestions: [],
@svsh227
svsh227 / cities.js
Created April 24, 2020 20:32
Create your own type ahead dropdown in React- Add cities in our app: Let's add some cities in our app so that we can enjoy searching by using our component. Create a file "cities.js" inside "src" folder and write below codes:
export default [
'Agra',
'Allahabad',
'Aligarh',
'Ambedkar Nagar',
'Auraiya',
'Azamgarh',
'Barabanki',
'Bijnor',
'Ballia',
@svsh227
svsh227 / apitest.js
Created April 16, 2020 11:17
# Write the test case: Now it’s time to write the test cases for our both API which is written on above server file. We will use mocha and chai to write the test cases. So lets start to write test case. Create a file with name apitest.js inside test folder ( myApp — -> test — -> apitest.js): Copy below code and paste into your apitest.js:
let chai = require(‘chai’);
let chaiHttp = require(‘chai-http’);
var should = chai.should();
chai.use(chaiHttp);
let server = require(‘../app’);//Our parent block
describe(‘Podcast’, () => {
describe(‘/GET media’, () => {
it(‘it should GET all the podcast’, (done) => {
chai.request(server)
@svsh227
svsh227 / server.js
Last active April 16, 2020 11:05
STEP 3: Create your server.js file
const express = require('express');
const app = express();
const port = 3300;
app.get('/message', function (req, res) {
res.send('This is the message');
});
app.get('/media', function (req, res) {
var response = {
@svsh227
svsh227 / package.json
Last active April 16, 2020 10:43
Write Test Cases for your node app using mocha. TEP 1: Create your package.json by using following command:
{
"name": "demotest",
"version": "1.0.0",
"description": "this is to understand the demo.",
"main": "server.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha — timeout 10000",
@svsh227
svsh227 / cliApp.js
Created April 16, 2020 08:12
Create init script to start the CLI application:
cli.init = function () {
/* Send the start message to the console in dark blue. */
console.log(‘\x1b[33m % s\x1b[0m’, ‘CLI is running’);
/* Start the interface */
var _interface = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: ‘>’
})