What is Node?
For more information about Node follow the link below:
Setting up the Environment
I took the reference of the given link https://blog.udemy.com.
For developing a Node-based application there are a few tools, which we have to install in our system. Here is a list of some basic tools which we need for Node application.
Install Text editor to build your code. Here is a list of text editor which you can install on your system.
Or you can use your Notepad editor.
After installing Mongo either you can run it from command prompt or window service.
https://nodejs.org by going to the given link you will get NPM (Node Package Manager) on your machine. By using NPM we can download packages/modules in our applications.
Install Express Generator
Express Generator is a Node module that we use to scaffold (platform) an application. To install Express Generator open a new Command Prompt and run the given command
Create a platform of your project which you want to develop using Node.
Enter the given command on command prompt after installing Express Generator,
Express project Name
Example: – express hello here hello is my project name.
Now open your project in your favorite text editor and the directory structure of your application will be like this:-
Routes defines an endpoint in your application where you receive requests.
App.js is the entry point to your application. Its where your application is defined and configured. This is the controller of your application.
Package.json this includes application metadata and identifies application dependencies. Here you will see your package.json structure:-
Here we will specify name and the version of our application as well as its dependencies.
To install the dependencies, go to terminal or command prompt and run the following commands:
To know more about the packages follow the link below:
Npm install nodemon -g
When you start a Node application, a basic web server starts on port 3000 and accepts incoming requests. If you make any changes in your application, you need to restart your application server so this is a time taking process to start the server after every alteration. So in order to overcome we use Nodemon, which is another Node module that automatically restarts your web server whenever it detects any change in your source files.
Monk is a Node module for reading and writing documents in MongoDB
To install monk follow the given command
Npm install monk save
How to run your application?
For running this basic application run the following command on your project directory on command prompt
Go to project by using
Then enter the command to run application
Nodemon will start your web server on port 3000, as shown in the above image.
Now launch your browser and navigate the given link:
Here is your first express application.