Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node js server get images from folder

// Requiring module
const express = require('express');
 
// Creating express object
const app = express();
 
// Defining port number
const PORT = 3000;                 
 
// Function to serve all static files
// inside public directory.
app.use(express.static('public')); 
app.use('/images', express.static('images'));
 
// Server setup
app.listen(PORT, () => {
  console.log(`Running server on PORT ${PORT}...`);
})
Comment

how to load image from dir nodejs


var fs = require('fs');
function(req,res){
  fs.readFile('image.jpg', function(err, data) {
    if (err) throw err; // Fail if the file can't be read.
      res.writeHead(200, {'Content-Type': 'image/jpeg'});
      res.end(data); // Send the file data to the browser.
  });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: gsap js link 
Javascript :: disable scroll on modal open 
Javascript :: angular show time ago 
Javascript :: vue event focus out 
Javascript :: count a character in a string, js 
Javascript :: onloadscroll to top 
Javascript :: how to disable back js 
Javascript :: javascript multiply array with scalar 
Javascript :: js remove item array 
Javascript :: js loop through array backwards with foreach 
Javascript :: addclass to elementref angular 
Javascript :: multiple line string in jquery 
Javascript :: disable global require eslint 
Javascript :: activeclassname in react router v6 
Javascript :: vaidate youtube url 
Javascript :: express redirect 
Javascript :: create a html table dynamically using javascript 
Javascript :: convert node.js to ES6 
Javascript :: javascript xor 
Javascript :: what 1hr in milliseconds in javascript 
Javascript :: how to hide button in react 
Javascript :: javascript to remove duplicates from an array 
Javascript :: upload multiple images cloudinary 
Javascript :: jquery select all checkboxes 
Javascript :: onclick inline function react 
Javascript :: Write the JavaScript code to set the width of element to 50%; 
Javascript :: tsconfig.json not generated 
Javascript :: swal change confirm button class 
Javascript :: js random numbers 
Javascript :: set data-id javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =