LoopBack 3 – Simple API with MongoDB Example

Expose your MongoDB NoSQL as a REST service with LoopBack 3 (Node.js Open API Framework)

This post is continuation of previous post. So if you want to start from beginning, read that one as well.

Follow this link to create a MongoDB Docker container 🙂

You can find LoopBack 3 project in the following repository. After clonning switch to mongodb branch 🙂 or run the following command.

git checkout mongodb

https://github.com/kenanhancer/loopback3-simple-api.git

LoopBack 3 – Simple API with MySQL Example

Expose your MySQL Database as a REST service with LoopBack 3 (Node.js Open API Framework)

This post is continuation of previous post. So if you want to start from beginning, read that one as well.

Follow this link to create a MySQL container 🙂

Node.js MySQL example will not start wihout running the following code in MySQL Database container. So, run the following command in terminal. If your Node.js app still doesn't connect, then try other options.

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your_root_password';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_root_password';

Run the following script for normal user.

ALTER USER 'foo'@'%' IDENTIFIED WITH mysql_native_password BY 'your_foo_password';
ALTER USER 'foo'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_foo_password';

Then run the following script

FLUSH PRIVILEGES;

You can find LoopBack 3 project in the following repository. After clonning switch to mysql branch 🙂 or run the following command.

git checkout mysql

https://github.com/kenanhancer/loopback3-simple-api.git

LoopBack 3 – Simple API Example

I am developing APIs with Node.js and LoopBack during last one year. So, it is time to create a post about it. 🙂 I try to build a detailed project. I hope that this post will be a good reference for developers.

Install LoopBack CLI Tools

There are two LoopBack CLI Tools.

You can also use the legacy StrongLoop CLI tool slc

Install LoopBack CLI Tool

$ npm install -g loopback-cli

This installs the lb command-line tool for scaffolding and modifying LoopBack applications.

Continue reading

Node.js Babel 6.x different usage transpiling to ES5 and Debugging

There are different usages of babel tool. I put a sample package.json file. Notice that there are scripts block which has different usages.

You can reach github project from the following link.

https://github.com/kenanhancer/babel6-usage.git

You can reach Babel 7.x post from the following link.

Creating Babel configuration file

.babelrc

{
  "presets": [
    "env"
  ],
  "plugins": [
    "transform-runtime"
  ],
  "sourceMaps": true,
  "retainLines": true
}

Running with Babel-node

//If you have installed babel-cli package globally, run below code.
babel-node --presets=env --plugins=transform-runtime src

or

//If you have .babelrc config file, run below code without specifying inline arguments.
babel-node src

or

//If you have installed babel-cli package locally, run below code.
./node_modules/.bin/babel-node --presets=env --plugins=transform-runtime src
Continue reading

Node.js Module Export and Import with CommonJS and ES6

I hope that this post will help any developer who need to see variations of importing and exporting modules. To be honest, due to using different programming languages, I sometimes forget some features so this post helped me every time 🙂

This is an other online code editor. Same examples is in this example as well.

CJS and ESM Usage Demo