How to convert value to string you have three ways Converting a value to string in JavaScript String(value) “” + value value.toString() value.toString is the worst. It doesn’t always work. So don’t use it. I personally use String(value) or “” + value How to use this (hard binding in javascript) this is a binding…
Tag: javascript
node.js fs – sclerotic
#How to read write files synchronously with fs
1 2 3 4 5 6 7 8 9 10 11 |
const fs = require('fs') const str = '1Hello world!' // save data fs.writeFileSync(`${__dirname}/data.html`, str) // read data const d = fs.readFileSync(`${__dirname}/data.html`, 'utf8') console.log('d = ', d) // d = 1Hello world! |
#How to read write files asynchronously with fs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
const fs = require('fs') const str = 'Hello world!' // save data fs.writeFile(`${__dirname}/data.html`, str, err => { if (err) throw err console.log('saved'); }) // read data fs.readFile(`${__dirname}/data.html`, 'utf8', (err, data) => { if (err) throw err console.log('data = ', data); // data = Hello world! }) |
#How to check existence of files Sometimes we have to know whether a file exists or not. To do this we’ll be using a node.js fs module. We could check synchronously by using and…
How to enable babel with nodejs and express
How to set up node.js with a ES6 support. You have to use them to modules that will allow you to wrap the server in a babel wrapper and the code will be work.
JavaScript tasks that will master skill
Doing these tasks on your own you’ll get very quickly a JavaScript master level These tasks will make a real practical skill. As know the repetition is a mother of the teaching. The usage instruction Select the task that you more like and start study code. Afterward when you know how the code works. Do the…
How to work with node.js modules
What is going on when we do require(‘some module’)? What if I want to include the MySQL module to my a few modules and use the same connection, how to have we include it properly? In this article, we’ll try to figure out how the node.js modules work. #How to make your own module Create a…
How to use passportjs with node.js
Links: the official site passportjs Look at my example on GitHub link Table contents: #Passportjs the usage scheme Usually you have to implement such a steps: create passport.serializeUser create passport.deserializeUser passport.use(new SteamStrategy({options}, callback) initialize the session, passport should be initialized afterward add two routers /auth/steam and /auth/steam/return #Passportjs general functions #Passport serialize…
JavaScript templates for rendering pages
Exists many JavaScript templates like handlebars, ejs, pug, etc. In this article I’ll overview some templates that I’ve used first of all it’s my the first template handlebars, I use the module express-handlebar links: How to integrate express with pug. The official guide link consolidate.js link Github repository with examples of this article link …
Where to start creating a node.js app. The detailed instruction for a newbie.
How to create a node.js app and where to start the newbies often ask these questions. In this article, we’ll try figuring out how it is going on. Node.js app has a few parts. It has always a config file. The content table: Create a config file #Create a config file We use…
How to use NPM. The main commands for a newbie
NPM is a node package manager, which is used for installing removing packages from the NPM repository link. You can publish your own packages there as well. The content table: NPM the common functionality How to use npm scripts #NPM the common functionality Create a package.json file we use the command
1 |
npm init |
Install…
React the basic course. From newbie to ninja
Hi. In this article I’ll explain to you how to use react. How to learn it the basic. To the end of which you will able to create powerful react app and will know some pitfalls. Let’s get started. I’m a new to React and decided to create this masterpiece like a crib where I’ll…