Node Js Code Samples


delete a folder in javascript
harika | 5 years, 7 months
// Delete the files recursively.
//fs is a built in node module.
const fs = require('fs');
fs.rmdir deletes the directory only if it empty. So for that we have to delete the files recursively
javascript node js
Command line arguments parsing in NodeJS with yargs and add a simple commands
kishore_kumar | 5 years
const yargs = require("yargs")

javascript node js
Check whether the file node is a directory or a plain file object
harika | 5 years, 7 months
//fs is a built in node module
const fs = require('fs');
const filePath = "/home/Desktop"
javascript node js
Write string or json objects directly to a file using node js
harika | 5 years, 7 months
const fs = require('fs');
//fs is a built in module in node js
const filePath = '/Desktop/Test.jso
javascript node js
Make a Get Request to url or to an api end point in Node JS
kishore_kumar | 5 years
const request = require("request")

const url = ""
javascript node js
Create a simple web server with express using Node js
kishore_kumar | 5 years
const express = require('express')

const app = express()
express javascript node js
Create a model and save document in Mongo db using Mongoose and Node JS
kishore_kumar | 5 years
const mongoose = require("mongoose")

mongoose.connect("mongodb://", {
mongoose javascript node js
Connect to Mongo DB and insert documents in Node JS
kishore_kumar | 5 years
const mongodb = require("mongodb")
const mongo_client = mongodb.MongoClient

javascript node js mongodb
Run shell files in javascript
harika | 5 years, 10 months
//JS Code
function runShellScript(){
    const process = require('child_process'); 
keep the function code inside the js file wherever you want to use. and keep the shell file provided
javascript shell node js
Compress files synchronously in javascript
harika | 5 years, 5 months
const tar = require('tar');
try to install 'tar' using npm and then try. Happy Coding :-)
node js javascript react js