Node.JS VS Express.JS
Wow, Today I am going to describe Node.JS and Express.JS. I hope after in this tutorial you will understand the concept of Node.JS and Express.JS. Okay, Let’s start.
Node.JS
What is Node.JS?
Node.js is a JavaScript runtime built on the V8 JavaScript engine.
Usage and Example of Node.JS
An example of a web server written with Node.js which response with 'Hello, World!':
Commands in this document start with $ or > to replicate how they would appear in a user's terminal. Do not include the $ and > characters. They are there to show the start of each command.
Lines that don’t start with $ or > character shows the output of the previous command.
First, make sure to have downloaded and installed Node.js. See this guide for further install information.
Now, create an empty project folder called projects, then navigate into it.
Linux and Mac:
$ mkdir ~/projects
$ cd ~/projectsWindows CMD:
> mkdir %USERPROFILE%\projects
> cd %USERPROFILE%\projectsWindows PowerShell:
> mkdir $env:USERPROFILE\projects
> cd $env:USERPROFILE\projectsNext, create a new source file in the projects folder and call it hello-world.js.
Open hello-world.js in any preferred text editor and paste in the following content:
const http = require('http');const hostname = '127.0.0.1';
const port = 3000;const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Save the file, go back to the terminal window, and enter the following command:
$ node hello-world.jsOutput like this should appear in the terminal:
Server running at http://127.0.0.1:3000/Now, open any preferred web browser and visit http://127.0.0.1:3000.
Get Shakil Ahmed’s stories in your inbox
Join Medium for free to get updates from this writer.
If the browser displays the string Hello, World!, which indicates the server is working.
Express.JS
The fast, unopinionated, minimalist web framework for Node.JS
Installing
Assuming you’ve already installed Node.js, create a directory to hold your application and make that your working directory.
$ mkdir myapp
$ cd myappUse the npm init command to create a package.json file for your application. For more information on how package.json works, see Specifics of npm’s package.json handling.
$ npm initThis command prompts you for a number of things, such as the name and version of your application. For now, you can simply hit RETURN to accept the defaults for most of them, with the following exception:
entry point: (index.js)Enter app.js, or whatever you want the name of the main file to be. If you want it to be index.js, hit RETURN to accept the suggested default file name.
Now install Express in the myapp directory and save it in the dependencies list. For example:
$ npm install express --saveTo install Express temporarily and not add it to the dependencies list:
$ npm install express --no-saveSimple Example
If you want to use Express.JS in your application. At first, you need to import Express.JS. Then you can use it. Example below →
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))Run the app with the following command:
$ node app.jsThis is simple. If you want to know more please visit for Express.JS and for Node.JS visit.
No more today. If you want to know more please search google and keep learning. If I make any mistakes please inform me by using my website www.shakilcse.me. I will try my best to solve it. Thank you all.







