logo
Published on

Create Your First Node JS Project

featured Image
Authors

JavaScript is the most popular language in the world. There are more than 2 billion websites in the world and 94% of them are using JavaScript. According to a StackOverflow survey, 68% of 70000 developers are using JavaScript and 44% are using python. JavaScript is the most used language according to Github's 2020 Report.

JavaScript is used to create web pages and it is executed in web browsers. React Js, angular Js, Next Js, and View Js are the most popular front-end development framework of JavaScript.

What is Node JS?

Node JS is the cross-platform, open-source, runtime environment for JavaScript that runs on chromium's V8 engine and executes JavaScript outside of web browsers. Node JS is asynchronous in nature so it is non-blocking. Node JS is being used by some top companies like LinkedIn, Uber, Paypal, eBay, medium. Some features of node js is listed below-

  • Non-blocking single-threaded (Asynchronous)
  • Multi-threaded using event loop
  • Cross-Platform
  • Faster development
  • Object-oriented
  • Large community
  • Can create a real-time application using socket

Installation

First, we need to download node js and npm (node package manager) on our system. Visit https://nodejs.org/en/download and download LTS(Long term support) version.

mern-stack

After downloading the node js setup, double click to install it. Follow installation steps and complete installation. After installation, you can check your installed version of node js and npm by running these commands-

node -v
# v14.17.3
npm -v
# v6.14.13

Create a project

So, now we are going to create our first node js project. Create a folder for the project. Inside the folder, open your terminal and run-

npm init

It will ask for some information about your project like project name, version, entry point. You can also run npm init -y to use default.

mern-stack

This will create a package.json inside your project. Now we have to install some dependencies like express js.

npm i express

Open your project with your code editor and create an index.js file. We will create a very small web server.

const express = require('express')

const app = express()

app.get('/', (req, res) => {
  return res.send('Hello World!')
})

app.listen('3000', () => {
  return console.log('Server is running')
})

To run your server-

node index.js

mern-stack

Open http://localhost:3000 in your browser.

mern-stack

That's all, we have created our first node js server. To learn node js, you can create some small projects like a to-do list, notes app.

Thanks for reading this article. If you have any queries, feel free to contact me: https://gyanendra.tech/#contact