Node Js Code Samples



Filters


Compress files synchronously in javascript
harika | 9 months, 3 weeks
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 | 11 months, 2 weeks
//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 | 11 months, 2 weeks
const fs = require('fs');
//fs is a built in module in node js
const filePath = '/Desktop/Test.jso
javascript node js
Run shell files in javascript
harika | 1 year, 2 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
Extract files synchronously in javascript
harika | 9 months, 3 weeks
const tar = require('tar');
  tar.x(
    {
Try to install tar module using npm and then try. Happy Coding :-)
node js javascript react js
Command line arguments parsing in NodeJS with yargs and add a simple commands
kishore_kumar | 4 months, 3 weeks
const yargs = require("yargs")

yargs.command({
javascript node js
Make a Get Request to url or to an api end point in Node JS
kishore_kumar | 4 months, 2 weeks
const request = require("request")

const url = "https://reqres.in/api/users"
javascript node js
delete a folder in javascript
harika | 11 months, 2 weeks
// 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
Connect to Mongo DB and insert documents in Node JS
kishore_kumar | 4 months, 2 weeks
const mongodb = require("mongodb")
const mongo_client = mongodb.MongoClient

javascript node js mongodb
Create a simple web server with express using Node js
kishore_kumar | 4 months, 2 weeks
const express = require('express')

const app = express()
express javascript node js
Next