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 :: how to disable copy paste in input js 
Javascript :: set header as json in laravel 
Javascript :: json typicode 
Javascript :: ajax done 
Javascript :: how to show 1 day ago in javascript 
Javascript :: type of data model mongodb 
Javascript :: redirect if not logged in next js 
Javascript :: get parameters from url 
Javascript :: react background image opacity 
Javascript :: how to use jquery timepicker 
Javascript :: change innertext javascript 
Javascript :: nextjs check production or development environment 
Javascript :: vue axios catch error 
Javascript :: express request body undefined 
Javascript :: remove url from string javascript 
Javascript :: useref 
Javascript :: reset select form jquery 
Javascript :: miles to metres js 
Javascript :: js clear a created list 
Javascript :: js page auto reload 
Javascript :: detect a click outside an element javascript 
Javascript :: sublime node 
Javascript :: js php number format 
Javascript :: axios network error react native 
Javascript :: js pass object property as a function parameter 
Javascript :: how to filter nested array of objects in javascript 
Javascript :: how to make one line if in js 
Javascript :: js foreach class 
Javascript :: foreach loop javascript 
Javascript :: Regular Expression for Detect Iranian Mobile Phone Numbers | IR mobile number Regex Pattern 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =