Code Monkey home page Code Monkey logo

node-starter's Introduction

๐Ÿ Node.js

Markdown Monster icon

  • Syncronized vs. Asyncronized?
  • OOP vs. Node.js?
  • What are the promises? Resolve Reject? Callback?
  • Where not to use async/await?
  • V8, Call Stack, Node APIs, Callback Queue, Event Loop

  1. Callback example:
fs.readFile("file1.txt", (err, data) => {
  if (err) throw new Error(err);
  console.log(data);
  console.log("Nisi lerdi ako nemas gicu");
});

console.log("Ona mala je ko kamen");
  1. Promise example:
const data = await fs.readFileSync("file1.txt");
console.log(data);
console.log("Nisi lerdi ako nemas gicu");

๐Ÿ“” Most used Node.js modules

  • express
  • dotenv
  • path
  • fs
  • axios / request-native-promise
  • moment
  • body-parser
  • cron
  • lodash
  • validator
  • nodemailer

  • mongoose
  • connect-mongo
  • express-session
  • bcrypt [Check if it's depricated]
  • cookieParser
  • jsonwebtoken
  • passport/passport-facebook/passport-jwt/passport-local
  • cors / helmet

๐Ÿ“ฝ Project Arhitecture

๐ŸŒฒ Structure of a project

โ”œโ”€ ๐Ÿ“ .vscode           [optional]
|   โ”œโ”€ ๐Ÿ“œ settings.json [optional]
|   โ””โ”€ ๐Ÿ“œ launch.json   [optional]
|
โ”œโ”€ ๐Ÿ“ node_modules (auto-generate)
|
โ”œโ”€ ๐Ÿ“ server
|   โ”œโ”€ ๐Ÿ“ api
|   |   โ”œโ”€ ๐Ÿ“ user
|   |   |   โ”œโ”€ ๐Ÿ“œ โ” index.js
|   |   |   โ”œโ”€ ๐Ÿ“œ user.routes.js
|   |   |   โ”œโ”€ ๐Ÿ“œ user.model.js
|   |   |   โ”œโ”€ ๐Ÿ“œ user.controller.js
|   |   |   โ”œโ”€ ๐Ÿ“œ user.service.js
|   |   |   โ””โ”€ ๐Ÿ“œ [singleton modules, services]
|   |   โ””โ”€โ”€ ...
|   |
|   โ”œโ”€ ๐Ÿ“œ server.js
|   โ”œโ”€ ๐Ÿ“œ router.js
|   โ””โ”€โ”€๐Ÿ“ services
|       โ”œโ”€ ๐Ÿ“œ logger.js
|       โ”œโ”€ ๐Ÿ“œ dbconfig.js
|       โ””โ”€ ๐Ÿ“œ [mostly singleton modules, services, mailer, middleware, varibales]
|
|
โ”œโ”€๐Ÿ“ public
|   โ”œโ”€๐Ÿ“ views [.ejs, .html, .pug...]
|   โ”œโ”€๐Ÿ“ scripts [frontend javascript files .js ]
|   โ”œโ”€๐Ÿ“ stylesheets [.css, less. cess...]
|   โ”œโ”€๐Ÿ“ images
|   โ””โ”€๐Ÿ“ assets [optional][media: files, audio, video...]
|
โ”œโ”€ ๐Ÿ“œ .eslintrc.json / .eslintrc.js
โ”œโ”€ ๐Ÿ“œ .package.json
โ”œโ”€ ๐Ÿ“œ .package-lock.json (auto-generate)
โ”œโ”€ ๐Ÿ“œ .gitignore
โ”œโ”€ ๐Ÿ“œ .env (.staging.env && .production.env)
โ”œโ”€ ๐Ÿ“œ Procfile (if you are deploying on heroku)
โ””โ”€ ๐Ÿ“œ README.md

๐Ÿ–ฅ About arhitecture

  • logger.js - morgan/winstong... logger configuration
  • dbconfig.js - mongo/dynamo/mysql... configuration
  • .env
  • .eslintrc.json - linter configuration
  • package.json - node project/packages configuration
    • NODE_ENV
    • dependecies
    • engine
    • scripts

api/<something>

  • <something>.routes.js - routers
  • <something>.model.js - DB collection
  • <something>.controller.js - logic
  • <something>.services.js - queries

๐Ÿ—ฏ Documentation comments

/**
*@description
*@return
*@params
*/
const functionName = [async]() => { };

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.