Skip to main content

Introduction to Node.js | A open-source server framework

What is Node.js?

  • Node.js is an open source server framework.
  • Node.js is free.
  • Node.js runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.).
  • Node.js uses JavaScript on the server.
  • Node.js files are saved with extension '.js'.

What Can Node.js Do?

  • Node.js can generate dynamic page content.
  • Node.js can create, open, read, write, delete, and close files on the server.
  • Node.js can collect form data.
  • Node.js can add, delete, modify data in your database.

How to download Node.js?


You can download and install node.js from the official website here. Node.js is cross-platform and can be used in almost all the OS.

Using Node.js:


You can edit node.js with any text editor. But I would recommend you to install and use Visual Studio Code which is cross-platform and also has IntelliSense that leads to faster coding. You have to add some extensions to edit node.js files more efficiently.

Creating Hello World Page:


To create a Hello World page, follow the steps mentioned:

  1. Create a file with the extension '.js'.
  2. Edit that file as follows:
  3. The above code tells the computer to write 'Hello World' if anyone i.e. web browser tries to open the port 8080.
  4. Node.js files must be initiated with command line interface(CLI).
  5. Open up your command line: For Windows: Open up Command Prompt. For Mac or Linux: Open up Terminal.
  6. Navigate to the folder that contains the '.js' file using 'cd' command. For example, my file is located in my Documents so the command will be: 'cd C:\Users\UserName\Documents'.
  7. Initiate the file using 'node fileName.js'. Here fileName is your file name.
  8. Do not close the command line interface.
  9. Now, open up the port which is http://localhost:8080/.
  10. "Hello World" will be displayed on your web browser.

Note: For Visual Studio Code, there is an integrated Terminal, which can be accessed from View>Integrated Terminal.

What is NPM?

NPM is a package manager for node.js files. It hosts thousands of free packages to be installed for free from their site named https://www.npmjs.com/. NPM is used to install node.js modules for your node.js application. Modules are JavaScript libraries that you can include in your project. 

How to install npm?

NPM comes along with Node.js. That means when you have installed Node.js, you have also installed npm alongside.

NPM can only be accessed from the command line using the command 'npm'. You can check whether npm is installed on your computer by entering 'npm -v' which would give you a version number else it is not installed. Installation of a module is done by the command 'npm install package_name'. Here, package_name is the name of the package.


Using a package on the Node.js application:

Downloading a package is very easy. Just open the command line interface and tell npm to install a package.


To terminate a node.js process use 'Ctrl-D' or 'Ctrl-C' twice.
In my example, I shall use upper-case package which converts all the letters of a word the uppercase. Follow the steps mentioned below:
  1. Write the code as follows:
  2. Save the file with extension '.js'
  3. Open up CLI and navigate to the directory of the file saved.
  4. Run the node server:> node fileName.js
  5. Open up the port http://localhost:8080/.
  6. All the letters of the word will be capitalised.
  7. Terminate the server process using 'Ctrl-D'.

Conclusion:

In this blog, we learned how to create a node.js application and the use of server framework with modules.

Comments

Popular posts from this blog

Creating a Web Browser With Integrated Chromium using C#

Final Output Introduction: In this post, we shall start a project to build a C# application integrated with Chromium in Visual Studio. I shall be using Visual Studio Express For Windows Desktop 2013. But the minimum requirements are mentioned below. We shall create a Windows Forms C# project from scratch and integrate Chromium Embedded Framework (CEF) in our application, basic navigation options and much more. Minimum Requirements and Prerequisites: Visual Studio 2012 or Higher that supports NuGet Package Manager. A decent internet connection. Basic Knowledge of C#. Knowlege in using Windows efficiently. Creating A Visual Studio Project: First, create a Visual Studio C# Project through File > New Project > Installed > Visual C# > Windows > Windows Forms . Name the file whatever you want, for example ' Web Browser '. New Project Customising the Form: Now customize the main form by changing its  Properties  like Text to 'Web...

How to start programming with JavaScript? Get Started with JavaScript!

Introduction: JavaScript is of-course a programming language. It can be called the 'programming language of the web' as it is one of the core three technologies for Web Development (other than HTML and CSS ). Before you start programming with JavaScript, you have to know what JavaScript is. See also: Basics of Programming Languages and Introduction to Front End Development . Requirements for this blog post: Minimum knowledge of programming terms: Intermediate . Minimum knowledge of JavaScript: None/Beginner . Some JavaScript Characteristics: JavaScript is a high-level , interpreted , dynamic and weakly-typed programming language. It is an object-oriented language like many high-level programming languages. It is a functional language , here function is considered to be an object. The term Vanilla JavaScipt is often used to refer JavaScript with any external frameworks or libraries. Best Free Resources to get started with JavaScript: After searchi...

Complete Guide to install Firebase CLI (Command Line Interface)

Source: firebase.google.com Introduction: Firebase is a mobile and web application development platform developed by Firebase, Inc. in 2011, then acquired by Google in 2014. It is one of the most popular platforms nowadays for developing Android applications. It is quite easy to, use with documentation for reference included on its website along with examples.  Firebase requires a browser to interact with. But, for advanced application development, it has a Command Line Interface (CLI) called Firebase CLI. It can be installed on your system, and then have to be used with your system's command line tool, such as Command Prompt in Windows, and Terminal in Linux and Mac. Installing in Windows: To install Firebase CLI, just follow the steps below: You must have installed Node.js and npm on your Windows system. To install refer the video below: Then type the following in your Command Prompt to install Firebase CLI: npm install -g firebase-tools That is it. You a...