한국어

Coding

온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
    
     라인상담
     라인으로 공유

    
페북공유

   ◎위챗 : speedseoul


  
     PAYPAL
     
     PRICE
     

pixel.gif

    before pay call 0088 from app


https://stackoverflow.com/questions/15463199/how-to-set-custom-favicon-in-express



I recently started working in Node.js and in the app.js file there is this line:

app.use(express.favicon());

Now, how do I set up my own custom favicon.ico?

    up vote188down voteaccepted

    In Express 4

    Install the favicon middleware and then do:

    var favicon = require('serve-favicon');
    
    app.use(favicon(__dirname + '/public/images/favicon.ico'));

    Or better, using the path module:

    app.use(favicon(path.join(__dirname,'public','images','favicon.ico')));

    (note that this solution will work in express 3 apps as well)

    In Express 3

    According to the API, .favicon accepts a location parameter:

    app.use(express.favicon("public/images/favicon.ico")); 

    Most of the time, you might want this (as vsync suggested):

    app.use(express.favicon(__dirname + '/public/images/favicon.ico'));

    Or better yet, use the path module (as Druska suggested):

    app.use(express.favicon(path.join(__dirname, 'public','images','favicon.ico'))); 

      No extra middlewares required. Just use:

      app.use('/favicon.ico', express.static('images/favicon.ico'));

      smiley favicon to prevent error:

       //const fs = require('fs'); 
       //const favicon = fs.readFileSync(__dirname+'/public/favicon.ico'); // read file
       const favicon = new Buffer('AAABAAEAEBAQAAAAAAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAA/4QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEREQAAAAAAEAAAEAAAAAEAAAABAAAAEAAAAAAQAAAQAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAP//AAD8HwAA++8AAPf3AADv+wAA7/sAAP//AAD//wAA+98AAP//AAD//wAA//8AAP//AAD//wAA', 'base64'); 
       app.get("/favicon.ico", function(req, res) {
        res.statusCode = 200;
        res.setHeader('Content-Length', favicon.length);
        res.setHeader('Content-Type', 'image/x-icon');
        res.setHeader("Cache-Control", "public, max-age=2592000");                // expiers after a month
        res.setHeader("Expires", new Date(Date.now() + 2592000000).toUTCString());
        res.end(favicon);
       });

      to change icon in code above

      make an icon maybe here: http://www.favicon.cc/ or here :http://favicon-generator.org

      convert it to base64 maybe here: http://base64converter.com/

      then replace the icon base 64 value

      general information how to create a personalized fav icon

      icons are made using photoshop or inkscape, maybe inkscape then photoshop for vibrance and color correction (in image->adjustments menu).

      for quick icon goto http://www.clker.com/ and pick some Vector Clip Arts, and download as svg. then bring it to inkscape (https://inkscape.org/) and change colors or delete parts, maybe add something from another vector clipart image, then to export select the parts to export and click file>export, pick size like 16x16 for favicon or 32x32. for further edit 128x128 or 256x256. ico package can have several icon sizes inside. it can have along with 16x16 pixel favicon a high quality icons for link for the website.

      then maybe enhance the image in photoshop. like vibrance, bevel effect, round mask, anything.

      then upload this image to one of the websites that generate favicons. there are also programs for windows for editing icons like https://sourceforge.net/projects/variicons/ .

      to add the favicon to website. just put the favicon.ico as a file in the root folder of the domain. for example in node.js in public folder that contains the static files. it doesn't have to be anything special like code above just a simple file.

        app.use(express.favicon(__dirname + '/public/images/favicon.ico')); 

        I had it working locally without the __dirname + but couldn't get it working on my deployed server.

          If you are using Express > 4.0, you could go for serve-favicon

            No need for custom middleware?! In express:

             //you probably have something like this already    
            app.use("/public", express.static('public')); 

            Then put your favicon in public and add the following line in your html's head:

            <link rel="icon" href="/public/favicon.ico">

            If you have you static path set, then just use the <link rel="icon" href="/images/favicon.ico" type="image/x-icon"> in your views. No need for anything else. Please make sure that you have your images folder inside the public folder.

            Install modules serve-favicon and path from npm, update index.js accordingly.

            //import packages
            var favicon = require('serve-favicon'), path = require("path");
            //use favicon icon path to access in application.
            app.use(favicon(path.join(__dirname+'/favicon.ico')));

            The code listed below works:

            var favicon = require('serve-favicon');
            
            app.use(favicon(__dirname + '/public/images/favicon.ico'));

            Just make sure to refresh your browser or clear your cache.

            번호
            제목
            글쓴이
            66 Android Login Registration System with Node.js and MongoDB – Server #1
            admin
            2017-12-24 34630
            65 Node.js를 이용하여 MySQL 데이터 가져오기
            admin
            2017-12-24 26311
            64 Using MySQL with Node.js & the mysql JavaScript Client 매우 설명 잘됨 공부 좋음
            admin
            2017-12-24 26231
            63 Android PHP MySQL 데이터베이스에서 데이터를 JSON 형식으로 가져오기
            admin
            2017-12-24 25839
            62 Android Login Registration System with PHP and MySQL (Updated) – Server #1
            admin
            2018-04-14 24253
            61 node.js로 서버를 구축하고 mysql을 데이터 베이스로 회원가입과 로그인 기능을 구현
            admin
            2018-06-23 20714
            60 노드에서 MySQL을 사용하는 방법 MySQL with Node.js and the mysql JavaScript Client
            admin
            2018-04-14 19875
            59 AWS 람다로 서버 없이 간단한 REST API 만들기
            admin
            2018-04-15 19733
            58 안드로이드 배우기: REST API 사용하기
            admin
            2018-05-06 19404
            How to set custom favicon in Express?
            admin
            2018-04-29 19068
            56 Android Login Registration System with PHP and MySQL (Updated) – Reset Password #3
            admin
            2018-04-14 18642
            55 Android Asynchronous Http Client A Callback-Based Http Client Library for Android
            admin
            2018-04-14 18383
            54 Android User Registration and Login with Node.js and MongoDB – Server #1
            admin
            2018-04-14 17366
            53 Node js 보안 Express
            admin
            2018-05-07 17117
            52 Android Login Registration System with PHP and MySQL (Updated) – Client #2
            admin
            2018-04-14 16911
            51 npm init 초기화
            admin
            2019-11-17 16781
            50 NODE.JS DATABASE MYSQL TUTORIAL
            admin
            2018-04-14 16571
            49 [Node.js] JWT(JSON Web Token)로 로그인 REST API 만들기 총 정리
            admin
            2018-06-14 16043
            48 Node.js paypal PayPal-node-SDK 사용해보자 상세한설명 연습 사례
            admin
            2018-01-15 15984
            47 NODE.JS REST API
            admin
            2018-04-14 15106
            46 Android에서 REST 요청 후 JSON 응답 받기
            admin
            2017-12-24 15036
            45 How can I read the data received in application/x-www-form-urlencoded format on Node server?
            admin
            2018-04-29 14987
            44 Node.js - mysql 연결
            admin
            2017-12-24 14502
            43 NodeJS를 이용한 API 서버만들기 3 자세한 설명 잘됨 매우 좋음 기초 노드
            admin
            2017-12-24 14471
            42 [node.js] express, 웹서버 구축, 설계, 제작
            admin
            2019-11-17 14302
            41 GET & POST Requests in Node.js Using Express-4
            admin
            2018-04-30 14214
            40 Android - JSON Parser JSONArray,JSONObject,JSONStringer JSONTokenizer
            admin
            2018-05-02 14041
            39 'Express' is not recognized command (windows) 기초
            admin
            2018-04-28 13954
            38 How to Setup Node.js and MongoDB in Ubuntu and Windows
            admin
            2017-12-24 13941
            37 serve-favicon install and how to
            admin
            2018-04-29 13888
            36 Getting Started with REST: Consuming simple REST APIs in Android
            admin
            2018-05-06 13829
            35 body-parser Learn about the anatomy of an HTTP transaction in Node.js
            admin
            2018-04-29 13770
            34 How to connect to a MySQL database with Node.js
            admin
            2018-04-14 13742
            33 How to handle the POST request body in Node.js without using a framework
            admin
            2018-04-29 13730
            32 Use ExpressJS to Get URL and POST Parameters
            admin
            2018-04-29 13691
            31 Consuming a JSON REST API in Android
            admin
            2018-04-14 13579
            30 node js 와 Jade 를 이용한 Database 를 홈페이지에 출력
            admin
            2018-06-23 13566
            29 RESTful Api using node.js,Express and Mysql
            admin
            2017-12-24 13563
            28 Node.js Parse JSON Little information to use JSON Data
            admin
            2018-04-14 13531
            27 Build a REST API for Your Mobile Apps using Node.js
            admin
            2017-12-24 13518
            26 Writing middleware for use in Express apps
            admin
            2018-04-29 13341
            25 nodejs windows 윈도우 노드 제이에스 설치 다운로드
            admin
            2018-01-15 13323
            24 node js 설치 install 리눅스 데비안
            admin
            2018-01-15 13322
            23 How do I send data to a Node.js server from an Android app?
            admin
            2018-04-14 13202
            22 MySQL Data Access API Development Using Express.JS, Node.JS
            admin
            2018-04-14 13153
            21 webstorm The smartest JavaScript IDE
            admin
            2018-06-02 13121
            20 NodeJS - Setup a Simple HTTP Server Local Web Server
            admin
            2018-01-07 13115
            19 RESTful Api using node.js,Express and Mysql
            admin
            2018-04-14 13089
            18 MySQL version 5.7.8 introduces a JSON data type
            admin
            2017-12-24 12908
            17 postman google
            admin
            2018-04-29 12863
            16 How can I send a post request with JSON from Android to a Node.js server?
            admin
            2018-04-14 12857
            15 Build a REST API for Your Mobile Apps using Node.js
            admin
            2018-04-14 12850
            14 JSON. Using the JSONObject in android and java.
            admin
            2017-12-24 12804
            13 Working with JSON in MySQL perfect
            admin
            2018-04-14 12731
            12 Check that you have node and npm installed
            admin
            2018-01-16 12665
            11 Your first Node.js HTTP server [ this chapter ]
            admin
            2018-01-07 12519
            10 Simple, unobtrusive authentication for Node.js passport facebook twitter gmail etc
            admin
            2018-01-07 12471
            9 mongodb 설치
            admin
            2018-01-15 12416
            8 Best Practices|| 128- Connect Android to MYSQL use Node.JS
            admin
            2017-12-24 12223
            7 Node.JS vhost 사용 설명
            admin
            2019-05-31 12089
            6 JavaScript & Node.js node 웹서버 구현 강의 설명 매우 잘됨 가장중요한 내용
            admin
            2019-11-20 11794
            5 Node.js SSL / TLS 인증서 갱신 실제 적용 방법 초간단 설명 재발급
            admin
            2019-05-26 11747
            4 How to build scalable node js and express website rest api
            admin
            2019-05-31 11425
            3 Hosting multiple websites using NodeJS and Express 멀티 도메인 호스팅
            admin
            2019-05-31 11413
            2 Node.js 익스프레스 웹 서버 Express-generator로 빠르게 설치하기
            admin
            2019-11-17 11261
            1 [Express.js] Express 로 웹 애플리케이션 만들기 express 사용법
            admin
            2019-11-17 11197