TitBits of Node.js — Part-2

📄 Table of contents

➤ Include CSS and JS files in Node.js

Create a connection between Node and JS

  • create a server on local machine using expressJS framework.
  • fetch json data using one of the get request on localhost:3000/fetchData.
  • send raw json data on button click via above post request.

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

I would suggest you create a public directory where you should keep all your javascript, CSS, images etc.

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

◉ run both client & server simultaneously

using concurrently package

npm install concurrently

◉ View Engines

.ejs, HandleBars

res.render(‘home’); //renders a view (engine) from noderes.send() // to send something from nodejs to frontendres.sendFile() // send file to frontend from nodejs# Whenever we have to send data (POST) to backend…we need to use a package body-parser .

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store