JavaScript(node.js)

[Mobile version(QRCode)]
Access record[Graph / PV Info.(Past 1 day / Past 1 week) / Access from outside (Yesterday / Past 1 week) / Vistors's list]
ProfilePmail(Mail)
Inbox   /Send   /Sent
Reviews(List   /Limit)
Poll   /Agree:Got   /Sent
Fan
Works/Music
Blog
[Write]
Links
My Play List
 Created dateCategoryArticle title
12017/11/05JavaScript(n..Syntax of Node.js
22017/08/06JavaScript(n..How to check undefined or ..
32017/07/23JavaScript(n..How to use ES6
42017/07/23JavaScript(n..How to publish your node.j..
52017/07/23JavaScript(n..Naming and coding style co..
62016/11/19JavaScript(n..How to update your local n..
 Created dateNameRecent messages

1.
2017/11/05 "JavaScript(node.js) > Syntax of Node.js"
[Show only this article / Modify / Delete / Send trackback / Add to the shared category]

1. About this Document
2. Asserting and Testing
3. Buffer
4. C++ Addons
5. C/C++ Addons - N-API

1. About this Document

This is based on Node.js v8.9.0
2. Asserting and Testing

https://nodejs.org/dist/latest-v8.x/docs/api/assert.html
assert(value[, message])
assert.deepEqual(actual, expected[, message])
assert.deepStrictEqual(actual, expected[, message])
assert.doesNotThrow(block[, error][, message])
assert.equal(actual, expected[, message])
assert.fail(message)
assert.fail(actual, expected[, message[, operator[, stackStartFunction]]])
assert.ifError(value)
assert.notDeepEqual(actual, expected[, message])
assert.notDeepStrictEqual(actual, expected[, message])
assert.notEqual(actual, expected[, message])
assert.notStrictEqual(actual, expected[, message])
assert.ok(value[, message])
assert.strictEqual(actual, expected[, message])
assert.throws(block[, error][, message])
Caveats
3. Buffer

Prior to the introduction of TypedArray in ECMAScript 2015 (ES6), the JavaScript language had no mechanism for reading or manipulating streams of binary data. The Buffer class was introduced as part of the Node.js API to make it possible to interact with octet streams in the context of things like TCP streams and file system operations.

Now that TypedArray has been added in ES6, the Buffer class implements the Uint8Array API in a manner that is more optimized and suitable for Node.js' use cases.

Instances of the Buffer class are similar to arrays of integers but correspond to fixed-sized, raw memory allocations outside the V8 heap. The size of the Buffer is established when it is created and cannot be resized.

The Buffer class is a global within Node.js, making it unlikely that one would need to ever use require('buffer').Buffer.
4. C++ Addons

Node.js Addons are dynamically-linked shared objects, written in C++, that can be loaded into Node.js using the require() function, and used just as if they were an ordinary Node.js module. They are used primarily to provide an interface between JavaScript running in Node.js and C/C++ librar
5. C/C++ Addons - N-API

N-API (pronounced N as in the letter, followed by API) is an API for building native Addons. It is independent from the underlying JavaScript runtime (ex V8) and is maintained as part of Node.js itself. This API will be Application Binary Interface (ABI) stable across versions of Node.js. It is intended to insulate Addons from changes in the underlying JavaScript engine and allow modules compiled for one version to run on later versions of Node.js without recompilation.

Add comment to this article

2.
2017/08/06 (Updated 2017/11/05) "JavaScript(node.js) > How to check undefined or null value of JavaScript's object or value"
[Show only this article / Modify / Delete / Send trackback / Add to the shared category]

1. Problem of checking valid value of JavaScript's object
2. How to install

1. Problem of checking valid value of JavaScript's object

To check the validness of JavaScript's object, you have to write very log description.
Example.
if (typeof geoinfo !== 'undefined' && geoinfo !== null && typeof geoinfo.geometry !== 'undefined' && geoinfo.geometry !== null && typeof geoinfo.geometry.location_type !== 'undefined' && geoinfo.geometry.location_type !== null) {
....
}

You can use @hikarine3/is-defined to check valid value of Javascript's object with ease.
After installation of npm and npm's module of "@hikarine3/is-defined," you can rewrite above sentence like this.

import isDefined from '@hikarine3/is-defined';
if (isDefined(geoinfo, "geometry.location_type")) {
...
}

Quite Simple.
If the tier of object is only 0 or 1, you can write this way.

import isDefined from '@hikarine3/is-defined';
if (isDefined(tier0obj)) {
...
}

import isDefined from '@hikarine3/is-defined';
if (isDefined(tier0obj.tier1)) {
...
}

2. How to install

If you have already installed npm, you can do like this.

npm install @hikarine3/is-defined;

Here is npm and github page.
https://www.npmjs.com/package/@hikarine3/is-defined
https://github.com/hikarine3/is-defined

Add comment to this article

3.
2017/07/23 No.3 "JavaScript(node.js) > How to use ES6"
[Show only this article / Modify / Delete / Send trackback / Add to the shared category]

npm init -y;

touch index.js;

npm install --save-dev babel-cli babel-preset-env;

Add comment to this article

4.
2017/07/23 (Updated 2017/07/24) "JavaScript(node.js) > How to publish your node.js package to npm repository"
[Show only this article / Modify / Delete / Send trackback / Add to the shared category]

1. Procedure
        1. Create project
        2. Coding
        3. Edit github info and so on
        4. Now publish
2. Reference

    1. Procedure


      1. Create project

PJ=test-pj
mkdir -p $PJ;
cd $PJ;
npm init -y;
      2. Coding

Create index.js at the root level
      3. Edit github info and so on

vi package.json;

Content will become like this.
{
  "name": "@hikarine3/is-defined",
  "version": "1.0.5",
  "description": "It is daunting task to check undefined variable especially when the item is nested object. Fundamental update of JS is ideal but this will help the problem until it is solved by JS itself.",
  "main": "distribution/index.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "build": "node ./node_modules/babel-cli/bin/babel source --presets babel-preset-env --out-dir .",
    "prepublish": "npm run build",
    "test": "node node_modules/babel-cli/bin/babel-node test/"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/hikarine3/is-defined.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/hikarine3/is-defined/issues"
  },
  "homepage": "https://github.com/hikarine3/is-defined#readme",
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-preset-env": "^1.6.0"
  },
  "dependencies": {}
}

      4. Now publish

npm adduser;

# Verify email

npm login;

npm publish --access=publish;

# Now you can install npm package at somewhere.
# In my case,
https://www.npmjs.com/~hikarine3
    2. Reference

https://docs.npmjs.com/getting-started/publishing-npm-packages

Add comment to this article

5.
2017/07/23 "JavaScript(node.js) > Naming and coding style conversion of JavaScript"
[Show only this article / Modify / Delete / Send trackback / Add to the shared category]

1. Naming and coding style conversion
    1. JavaScript (ES6)
        1. File encoding
        2. File names
        3. Package names
        4. Class names
    2. Object names
        1. Method names
        2. Enum names
        3. Constant names
        4. Parameter names
        5. Local variable names
        6. Variable Names
        7. Functions
        8. Spaces Around Operators
        9. Code Indentation
        10. Object Rules
        11. Line Length
        12. Empty blocks
        13. Loading JavaScript in HTML (ES6)
    3. React
        1. Reference Naming
        2. Component Naming
        3. Quotes
        4. Props
        5. Tags
        6. Bind
        7. Function naming
    4. Reference

1. Naming and coding style conversion

Naming convention is important and useful to develop as at team.
I will put summary of naming conversion for javascript (node.js, react)
    1. JavaScript (ES6)


      1. File encoding

Source files are encoded in UTF-8.
      2. File names

File names must be all lowercase and may include underscores (_) or dashes (-), but no additional punctuation. Follow the convention that your project uses. Filenames’ extension must be .js.
      3. Package names

lowerCamelCase
      4. Class names

Class, interface, record, and typedef names are written in UpperCamelCase
    2. Object names

lowerCamelCase
      1. Method names

Method names are written in lowerCamelCase. Private methods’ names must end with a trailing underscore.
      2. Enum names

Enum names are written in UpperCamelCase
      3. Constant names

Constant names use CONSTANT_CASE: all uppercase letters, with words separated by underscores.
      4. Parameter names

Parameter names are written in lowerCamelCase
      5. Local variable names

Local variable names are written in lowerCamelCase, except for module-local (top-level) constants
      6. Variable Names

camelCase
      7. Functions

camelCase
      8. Spaces Around Operators

Always put spaces around operators ( = + - * / ), and after commas:
      9. Code Indentation

Each time a new block or block-like construct is opened, the indent increases by two spaces.
      10. Object Rules

Place the opening bracket on the same line as the object name.
Use colon plus one space between each property and its value.
Use quotes around string values, not around numeric values.
Do not add a comma after the last property-value pair.
Place the closing bracket on a new line, without leading spaces.
Always end an object definition with a semicolon.
      11. Line Length

Keep less than 80.
For readability, avoid lines longer than 80 characters.
If a JavaScript statement does not fit on one line, the best place to break it, is after an operator or a comma.
      12. Empty blocks


An empty block or block-like construct may be closed immediately after it is opened, with no characters, space, or line break in between (i.e. {}), unless it is a part of a multi-block statement (one that directly contains multiple blocks: if/else or try/catch/finally).

Example:
function doNothing() {}

      13. Loading JavaScript in HTML (ES6)

Use simple syntax for loading external scripts (the type attribute is not necessary):
    3. React


      1. Reference Naming

Extensions: Use .jsx extension for React components.
Filename: Use PascalCase for filenames. E.g., ReservationCard.jsx.
Reference Naming: Use PascalCase for React components and camelCase for their instances. eslint: react/jsx-pascal-case
      2. Component Naming

Use the filename as the component name. For example, ReservationCard.jsx should have a reference name of ReservationCard. However, for root components of a directory, use index.jsx as the filename and use the directory name as the component name:
      3. Quotes

Always use double quotes (") for JSX attributes, but single quotes (') for all other JS. eslint: jsx-quotes
<Foo bar="bar" />
<Foo style={{ left: '20px' }} />
      4. Props

Always use camelCase for prop names.
Omit the value of the prop when it is explicitly true.
Do not use words like "image", "photo", or "picture" in <img> alt props.
      5. Tags

If your component has multi-line properties, close its tag on a new line. eslint: react/jsx-closing-bracket-location
      6. Bind

Bind event handlers for the render method in the constructor. eslint: react/jsx-no-bind
Why? A bind call in the render path creates a brand new function on every single render.
      7. Function naming

Do not use underscore prefix for internal methods of a React component.
Why? Underscore prefixes are sometimes used as a convention in other languages to denote privacy. But, unlike those languages, there is no native support for privacy in JavaScript, everything is public.
    4. Reference

https://google.github.io/styleguide/jsguide.html
https://www.w3schools.com/js/js_conventions.asp
https://github.com/airbnb/javascript/tree/master/react

Add comment to this article

6.
2016/11/19 No.3 "JavaScript(node.js) > How to update your local node.js to the latest version"
[Show only this article / Modify / Delete / Send trackback / Add to the shared category]

npm install -g n;
n --latest;
n latest;
npm update -g npm;
npm update -g;

Add comment to this article
Subscribe to RSS
RSS
Display Style of blog
List/Mobile(QRCode)
Term
Category
All
1.Japan
2.Atlassian's products
3.Self
4.Development of this site
5.Japanese comics
6.Japanese anime
7.Weekly hot news of Japanese culture
8.OP/ED/PV
9.Japanese game
10.Ranking
11.Japanese Comics (Manga)
12.Search Engine
13.Japanese drama
14.Japanese otaku culture
15.Programming
16.Ineternet world
17.Movie
18.C/C++
19.BerkeleyDB
20.Apache programming
21.Spam
22.Meteor
23.Marketing
24.Python
25.Scrum
26.JIRA
27.Git
28.CI
29.Jenkins
30.AWS
31.Operation
32.Singapore
33.Cloud
34.Mysql Cluster
35.DevOps
36.Bitbucket
37.Xamarin
38.Good and new
39.Monitoring
40JavaScript(node.js)
41.React
42.Phillipines
43.Hiring
44.Python
45.SEO
46.Malaysia
47.Mongodb
48.Perl
49.Docker
50.Life hack
51.Dance
52.QA
53.Mysql
54.Digital Life Hack
Sayings from S-Cry-Ed

Rule in this world is speed. Even stupid person can write cool novel if he can spend 20 years for it.

If someone helped me, I will help him in return, which is my rule.

To become stronger, consider what is cowardliest thinking. And rebel against the thinking, which will make you stronger.



I am Japanese but working for some English sites.

Doctor Job Career
Nurse Job Career
Top Page top MetaSeachJP Works