TitBits of Node.js — Part-2

📄 Table of contents

Create a connection between Node and JS

◉ Serve Static Files (Include CSS and JS files in Node.js)

app.use(express.static(path.join(__dirname, 'public')));
var express = require('express');
var path = require('path');
<link rel='stylesheet' href='/style.css' />

Template Engines with Express

app.set("view engine", "hbs"); // mandatory to write in same format

◉ run both client & server simultaneously

npm install concurrently

◉ View Engines

// to send something (raw text) from expressJS to FE
res.send("send sthg to FE");
// to send HTML tag from expressJS to FE
res.send("<h1> sending html tag</h1>");
res.sendFile() // send file to frontend from nodejs//renders a view (when we are using render engines) in express
res.render(‘index’);
# Whenever we have to send data (POST) to backend…we need to use a package body-parser .

Use Express.JS as a Web Server

const express = require('express');
const app = express();
app.get('/', (req,res)=> { //get method
res.send('Hello World'); //send response});
app.listen(3000);

Express Application Generator

Getting started

npx express-generator

Creating a project

express myProject #create a project with name of myProject
cd myProject #change working directory to myProject
npm install #install all required dependencies
npm start

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.