My first backed Program
Table of contents
- when we wright npm init ,it will going to ask certain Question and if you want to edit or update anything Like (program name author name you can do it as you like ) and if you want default setting or avoid this questionnaires you can simply wright
- so now we can say that we created our first node js app After writing a simple code.
- Now We need to create Index.js file but ... why?
- index.js
- To avoid repetition of run the program when we can make any changes ,we can install NODEMON.
- Thank you
How to Create Express Backend program
lets understand step by step:-
First we need to go to the directory and folder-where we want to create our node js program so we will use command prompt in our pc. ( let suppose FSJS is the folder and the location is desktop so can write )
cd location / folder name ( cd Desktop/FSJS )-code
- Then we need to make a directory called as Socialmediaapp so next we need to wright on command prompt.
This is the directory name where i am going create myapp So to go into the directory i am going wrightfolder name/directory name ( FSJS mkdir Socialmediaapp )-code
FSJS cd Socialmediaapp Socialmediaapp code .
- Then we will wright
Socialmediaapp npm init
when we wright npm init ,it will going to ask certain Question and if you want to edit or update anything Like (program name author name you can do it as you like ) and if you want default setting or avoid this questionnaires you can simply wright
Socialmediaapp npm init -y
- Then we well the packeage.json file which contains all details of the program
{
"name": "socialmediaapp",
"version": "1.0.0",
"description": "My First Backend program",
"main": "index.js",
"scripts": {
"test": "echo\"Error: no test specified \"&& exit 1"},
"author": "Rahul Parmar",
"license": "ISC",
so now we can say that we created our first node js app After writing a simple code.
cd Desktop/FSJS
FSJS mkdir Socialmediaapp
FSJS cd Socialmediaapp
Socialmediaapp code .
Socialmediaapp npm init
Now We need to create Index.js file but ... why?
Ans: Because when we wright npm start ,so it is going to go inside script and search for command which is going to run the script and search the script file which is going to run . so as per previous program we don't have any start command and script file so we have to create a index.js file(it is also known as entry point) and we need do some changes in previous code and need to add a start command and index.js file in the program then the code will be as follows -To run this node js program first we need to install an famous app called as Express app so we need to wright
socialmediaapp npm i express
socialmediaapp npm i nodemon
socialmediaapp npm start
{
"name": "socialapp",
"version": "1.0.0",
"description": "My First Backend program",
"main": "index.js",
"scripts": {
"start": "nodemon index.js"
},
"author": "Rahul Parmar",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"nodemon": "^2.0.22"
}
}
index.js
console.log("hello world");
Output
hello would
To avoid repetition of run the program when we can make any changes ,we can install NODEMON.
what nodemon do? Ans: nodemon is a tool that helps develop Node.js based applications by automatically restarting the node application when file changes in the directory are detected. and it can be install just to write "npm i nodemon"
Thank you
Subscribe to my newsletter
Read articles from Rahul directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by