Skip to content

Instantly share code, notes, and snippets.

@myogeshchavan97
myogeshchavan97 / is_field_valid_es6.js
Created November 23, 2019 18:58
Field Validation Using ES6 Syntax
const isNotEmpty = fieldName => fieldValue => fieldValue.trim().length > 0 || fieldName[0].toUpperCase() + fieldName.slice(1) + ' is required.';
const fieldName = isNotEmpty('name');
let isValid = fieldName('David');
console.log(isValid); // true
isValid = fieldName('');
console.log(isValid); // Name is required
@myogeshchavan97
myogeshchavan97 / express_start.js
Created November 26, 2019 11:28
Initial Express Code
// section 1
const express = require('express');
const app = express();
// section 2
app.get('/', (req, res) => {
res.send("<h1>Welcome to the world of Express!</h1>");
});
// section 3
@myogeshchavan97
myogeshchavan97 / start_script.js
Created November 26, 2019 11:32
Start Script
"scripts": {
"start": "nodemon index.js"
}
@myogeshchavan97
myogeshchavan97 / users.js
Created November 26, 2019 11:39
List of users
const users = [{
firstName: 'David',
lastName: 'Jonhnson',
email: 'david@gmail.com'
}, {
firstName: 'Renn',
lastName: 'Mead',
email: 'renn@gmail.com'
}];
@myogeshchavan97
myogeshchavan97 / index.html
Created November 26, 2019 11:45
Index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
@myogeshchavan97
myogeshchavan97 / post_route.js
Created November 26, 2019 11:53
Post Route
app.post('/users', (req, res) => {
users.push(req.body);
res.send(users);
});
@myogeshchavan97
myogeshchavan97 / index.js
Created November 26, 2019 11:55
Index js file
// section 1
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
// section 2
app.get('/', (req, res) => {
res.send("<h1>Welcome to the world of Express!</h1>");
@myogeshchavan97
myogeshchavan97 / help.html
Created November 26, 2019 11:56
help.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>This is just a help file.</h1>
@myogeshchavan97
myogeshchavan97 / index.html
Last active April 9, 2021 07:32
Index html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="root"></div>
@myogeshchavan97
myogeshchavan97 / webpack.config.js
Last active April 9, 2021 08:51
Webpack Configuration File
const path = require('path');
module.exports = {
entry: './src/app.js',
output: {
filename: 'bundle.js',
path: path.join(__dirname, 'public')
}
};