Node Js Code Samples



Filters


delete a folder in javascript
harika | 2 years, 5 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 | 1 year, 11 months
const yargs = require("yargs")

yargs.command({
javascript node js
Write string or json objects directly to a file using node js
harika | 2 years, 5 months
const fs = require('fs');
//fs is a built in module in node js
const filePath = '/Desktop/Test.jso
javascript node js
Compress files synchronously in javascript
harika | 2 years, 4 months
const tar = require('tar');
  tar.c(
    {
try to install 'tar' using npm and then try. Happy Coding :-)
node js javascript react js
Check whether the file node is a directory or a plain file object
harika | 2 years, 5 months
//fs is a built in node module
const fs = require('fs');
const filePath = "/home/Desktop"
javascript node js
Make a Get Request to url or to an api end point in Node JS
kishore_kumar | 1 year, 10 months
const request = require("request")

const url = "https://reqres.in/api/users"
javascript node js
Run shell files in javascript
harika | 2 years, 8 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
Create a simple web server with express using Node js
kishore_kumar | 1 year, 10 months
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 | 1 year, 10 months
const mongoose = require("mongoose")

mongoose.connect("mongodb://127.0.0.1:27017/my-db", {
mongoose javascript node js
Connect to Mongo DB and insert documents in Node JS
kishore_kumar | 1 year, 10 months
const mongodb = require("mongodb")
const mongo_client = mongodb.MongoClient

javascript node js mongodb
Next