Insert ASCII in variable in Node.js

376
April 23, 2017, at 04:24 AM

I'm trying to insert this ascii img:

                              :hNMMh.             
                             .sosooNm`            
                             +sosysyds            
                             s+o/oossy:           
              `.`  -+shho++soy+oo+osyoy:::...`    
     `o:`  `+yhhhoyhhyds/-:-os++oshhsos+/+////+/: 
      oyo//yyyyyyyyhhyhyyssoyymmNmyo///+oosyyyhhd-
      /+shhhhhddhdmhyyyyyyyyyyyyyyysyhhhyyyyyyyyho
     :o+//////+osddyyyyyyyyyyyyyyyyyyyhdhyyyyyyyyd
    `:`          -mhyyyyyyyyyyyyyyhhdmdddhyyyyyyhN
                 ydyyyyyyyyhhhhddmmmdmmddhhyyyyhdm
                 :dhyhyysyhyyyyhhyyhddmdhysyyhyhyd
    .-:-`         :dhyyyyyyhyyyhyyyyyssdhysyyddyyy
  .//::///-`       :dyyyyyyyyyd+://::+:+hdhhhdhyh/
 :/----:::///-.`    +hy+yyysssh::+::/+/sdhyyyyyyh`
-/---------::////:-.-h+://+///y+/+soooddhyyhhyyh- 
o-----------------://dy+:-:+syyd/+hso+hhhhhhyso-  
+::///:::::::::--::::sdhyshhyyyyh:/ssso/s++y`     
       ```.o/://://///mhyhddhyyyhs--//://-+:      
           `o--:::::::ydyyymdhyyyd:-:://--o       
            /:--------:dyyhsydhyyhs-:/:--+`       
             +:-------:syyd:-odhyyd/:--:+`        
        `.    :/:--:/::-dhhhyo+dhyhs:-//`         
         ++:.`  ....:/--odyyym::mhyhhys           
          ///:::::::++///d//sh--ydyyyyh+          
           -+---------:::+s-:s-:+hhyhy/y          
            `//--------:::h:+o:-  :sos-y          
              .:/-----:/+sy/s-      /o-o:         
                 ------++/-:++       .s/s`        
                    /yyo+/:-          `y:o/       
                     ``                -s-:o-     
                                        s:-:+o.   
                                        .so++//    

In a variable to log it in the terminal, but I can't close the " or '. any idea?

Answer 1

There are many ways to achieve this, but in my opinion the best one is to store this text in a file (image.txt for example), and read it with the fs module like this

var image = fs.readfilesync('image.txt');
console.log(image);
Answer 2
  1. First of all use literals `` or readFile for keeping new lines and spaces.
  2. Make sure that your terminal use monotype font, because you need the same width for every character.
Answer 3

I'm guessing you must be doing something like this:

var test = 'khsadlkjhk
khsgfjds';

Because next lines in javascript are treated as end of statement, you cannot store the whole text above directly into a variable in node.js. You can either save the variable using multi-line strings, or Template literals.

Do it like this:

var test = `string text line 1
string text line 2`;

Notice the use of backticks (`) instead of inverted commas

Rent Charter Buses Company
READ ALSO
node.js passport user schema set it manualy

node.js passport user schema set it manualy

first sorry for my english ;) second my question :

315
css js not linking to linked html file when using node server

css js not linking to linked html file when using node server

I am trying to serve static files likecss

335
Is it possible to use CORBA reliably from nodejs?

Is it possible to use CORBA reliably from nodejs?

I'm looking at possibly moving from Java servlets which interact with C++ via CORBA calls to a NodeJS backend but I've only found two incomplete projects to implement CORBA on nodejsIs there something about the NodeJS architecture that makes it incompatible...

623
How to execute loacl server linux command on terminal using Node.js?

How to execute loacl server linux command on terminal using Node.js?

I am trying to execute a Nodejs script for Motion

428