Creation of a simple node js application Installation and connection with DB Basic Commands used for the installtion Starting the application To install a basic simple app for node firstly need to check the node version on the system If node is not installed check the following documents for the node installation Node.js — Download… Continue reading Creating Simple Node js Application
Tag: node js
Connect Node JS with Mongo DB
Select the project from the Node JS and create a database inside the project. Username and password are to be needed to be used in further step. Select the database from the list and click on connect to get the connection string. Click on Drivers. Use the connection string with the code in the Node… Continue reading Connect Node JS with Mongo DB
Logging request with “Morgan” in Node JS.
To log requests using Morgan in Node.js, you first need to install the Morgan package: npm install morgan Then, you can integrate Morgan into your Node.js application. Here’s an example of how you can use Morgan with Express.js: const morgan = require(‘morgan’); and use it below where Cors are used. // Use Morgan middleware to… Continue reading Logging request with “Morgan” in Node JS.
Set up build folder in server files in React-Node Js.
You can use cross-env, a package that sets environment variables across platforms. First, install cross-env as a dev dependency: npm install cross-env –save-dev Then, modify your build script to use cross-env to set the BUILD_PATH: “scripts”: { “dev”: “react-scripts start”, “build”: “cross-env BUILD_PATH=../server/public react-scripts build”, “test”: “react-scripts test”, “eject”: “react-scripts eject” }, Now, when you… Continue reading Set up build folder in server files in React-Node Js.
Run client and server together in Node JS using concurrently
To run the client and server together in Node.js using concurrently, you need to ensure that both the client and server processes are started concurrently. You can do this by creating a script in your root package.json that utilizes concurrently to start both processes. Here’s how you can modify your package.json { “name”: “nasa-project”, “version”:… Continue reading Run client and server together in Node JS using concurrently
Enable Cors in Node js
To enable CORS (Cross-Origin Resource Sharing) in a Node.js application, you can use the cors middleware package. Here’s how you can do it: First, install the cors package via npm npm install cors Once installed, you can use it in your Node.js application by requiring it and applying it to your Express application. const express… Continue reading Enable Cors in Node js
How to get the filename extension in a NodeJS environment
The built-in extname() method from the path module returns the extension of the string path from the last occurence of the period . character to the end of the string. When no period character is found, the method will return an empty string: const path = require(“path”); path.extname(“index.md”); // .md path.extname(“index.”); // “.” path.extname(“index”); //… Continue reading How to get the filename extension in a NodeJS environment
Understanding the Phases of Node.js: A Comprehensive Guide
Node.js, a powerful and versatile JavaScript runtime, is widely used for building scalable and high-performance applications. One key aspect that sets Node.js apart is its event-driven, non-blocking I/O model, which is orchestrated through a series of phases. In this article, we will delve into the various phases of Node.js and explore how they contribute to… Continue reading Understanding the Phases of Node.js: A Comprehensive Guide
Ineffective mark-compacts near heap limit allocation failed – JavaScript heap out of memory
JavaScript’s heap out of memory error typically occurs when the Node.js environment runs out of memory during garbage collection due to heavy memory usage or memory leaks. This guide provides actionable solutions for engineers to troubleshoot and resolve this error. Understanding the error When Node.js applications consume more memory than what is available, V8 triggers… Continue reading Ineffective mark-compacts near heap limit allocation failed – JavaScript heap out of memory
What is evented I/O for V8 JavaScript?
Evented I/O for V8 JavaScript is the core design principle behind Node.js, enabling non-blocking, asynchronous operations. It lets JavaScript code perform I/O operations without waiting for each to complete, which can make applications more efficient and performant. Understanding evented I/O Evented I/O is built around events and callbacks. When an I/O operation is initiated, it… Continue reading What is evented I/O for V8 JavaScript?