Standard Way To Create Node JS Fresh Project

As you know in programming world JavaScript is becoming quite famous programming language so in this blog we will discuss how we can create fresh project of NodeJS in standard way.

NodeJS - Education Funda
NodeJS - Education Funda

Requirements

  • Any server should be installed either Apache or Nginx.
  • NodeJS and NPM should be installed in the operating system. 

Steps to Install Fresh Node JS Project:

First open your terminal and go to your project directory then run following commands

~ npm init (after hitting this command it will ask some basic questions you can answer it as per your need.
 
~ npm init

~ npm install express (it will install express server for your project)
~ npm install mongodb (optional - if you want to use mongo)
~ npm install mongoose (optional - if you want to use mongo)
~ npm install nodemon --save-dev (nodemon package is using for automatically refresh after any change and we're using save dev here because we want to install it for development purpose only)

To do setup of license, .gitignore and code of conduct for new project we can do with NPX commands:

~ npx license mit (it will create open source license for your project)
~ npx gitignore node (it will create .gitignore file in your project automatically so you don't need to create it manually) 
~ npx covgen your_email_id (it will create code of conduct file for your project)

Now you can create app.js OR index.js file in your project directory which you mentioned while npm init also, below is example file

"use strict"
const express = require('express')
const mongoose = require('mongoose')
const app = express() 
const port = 8000 
 
// connect to db
mongoose.connect(server.dbUrl, {useNewUrlParser:true})
const conn = mongoose.connection
conn.on('open', () => {
console.log('database connected...')
})

// listen server
app.listen(port,"0.0.0.0", () => {
    console.log(`Server listening on port ${port}!`)
})

That's it from these commands now you have just created your standard way of code node js project.
 
 
I hope you like our effort, please share your feedback in comments sections !!


Comments

Popular posts from this blog

JavaScript Logical Output Based Interview Questions

Create and Deploy AWS SAM Application

Deploy Angular Build With Express JS Project