Difference between revisions of "My Node.js notes"

From Got Opinion Wiki
Jump to navigation Jump to search
m (added sockets.io)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Node.js install ==
Go to [https://nodejs.org https://nodejs.org] and follow instructions for the Node.js version you want or install via Node Version Manager (NVM).
There are multiple ways to install NVM. I used NVM BASH script and instructions located 
[https://github.com/nvm-sh/nvm#installing-and-updating here] for Ubuntu 20.
== Node Version Manager (NVM) ==
[[My Node Version Manager (NVM) notes]]
== Node.js Package Manager (npm)==
== Node.js Package Manager (npm)==


Line 20: Line 31:


debugger statement and <code>node inspect</code>
debugger statement and <code>node inspect</code>
Windows users may need to use <code>node --inspect-brk</code>


<pre>chrome:://inspect</pre>
<pre>chrome:://inspect</pre>
Line 77: Line 90:
HTTP assertions made easy via superagent. The motivation with [https://www.npmjs.com/package/supertest supertest] is to provide a high-level abstraction for testing HTTP, while still allowing you to drop down to the lower-level API provided by superagent.
HTTP assertions made easy via superagent. The motivation with [https://www.npmjs.com/package/supertest supertest] is to provide a high-level abstraction for testing HTTP, while still allowing you to drop down to the lower-level API provided by superagent.


[https://www.npmjs.com/package/socket.io Socket.IO] enables real-time bidirectional event-based communication.
[https://www.npmjs.com/package/socket.io Socket.IO] enables real-time bidirectional event-based communication. [https://socket.io/ Socket.IO] home
 
[https://www.npmjs.com/package/bad-words bad-words] is a javascript filter for badwords.
 
[https://www.npmjs.com/package/moment moment] is a lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.


== Resources ==
== Resources ==

Latest revision as of 10:12, 16 December 2021

Node.js install

Go to https://nodejs.org and follow instructions for the Node.js version you want or install via Node Version Manager (NVM).

There are multiple ways to install NVM. I used NVM BASH script and instructions located here for Ubuntu 20.

Node Version Manager (NVM)

My Node Version Manager (NVM) notes

Node.js Package Manager (npm)

npm

Initialize an npm project. Within project directory use npm init command. The default command launches a questionnaire. To answer default on all questions use -y argument.

Uninstall global module

npm uninstall -g nodemon

Install local module

npm install nodemon

Install as dev dependency (not installed on production environment)

npm install nodemon --save-dev

Basic stuff

debugger statement and node inspect

Windows users may need to use node --inspect-brk

chrome:://inspect

Exit Chrome DevTool debugger.

Type restart at console after exiting Chrome DevTool to restart app with same arguments.

Press CTRL+C twice to exit debugger in console.

nodemon

If nodemon installed globally

nodemon <app.name> -e <comma separated list of extensions to monitor>

If nodemon installed locally a script can launch. See scripts key section for details.

package.json info

scripts key

create key value pair where key is name of script and value is script location

Example:

"scripts": {
    "dev": "nodemon src/app.js -e js,hbs"
  }

At node prompt type npm run dev to execute script nodemon src/app.js -e js,hbs

NPM modules

CORS is a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.

The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.

Mongoose provides a straight-forward, schema-based solution to model your application data. It includes built-in type casting, validation, query building, business logic hooks and more, out of the box.

validator is a library of string validators and sanitizers.

bcryptjs is optimized bcrypt in JavaScript with zero dependencies. Compatible to the C++ bcrypt binding on node.js and also works in browser.

jsonwebtokens is an implementation of JSON Web Tokens.

Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files. It is written on top of busboy for maximum efficiency.

busboy is a node.js module for parsing incoming HTML form data.

sharp is a high speed node.js module that convert large images in common formats to smaller, web-friendly JPEG, PNG and WebP images of varying dimensions.

env-cmd is a simple node program for executing commands using an environment from an env file.

jest is a delightful JavaScript testing library

mocha is a simple, flexible, fun JavaScript test framework for Node.js & the browser

HTTP assertions made easy via superagent. The motivation with supertest is to provide a high-level abstraction for testing HTTP, while still allowing you to drop down to the lower-level API provided by superagent.

Socket.IO enables real-time bidirectional event-based communication. Socket.IO home

bad-words is a javascript filter for badwords.

moment is a lightweight JavaScript date library for parsing, validating, manipulating, and formatting dates.

Resources

Node.js home

regex 101

To software notes