Backend Development: NPM and Modules
34 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the primary purpose of npm?

  • To compile JavaScript code into machine code
  • To manage project dependencies and packages (correct)
  • To create graphical user interfaces
  • To serve web pages
  • NPM was created in 2011 and is maintained by Google.

    False

    What command is used to initialize a new Node.js project?

    npm init

    The package.json file contains _______ about the Node.js project and lists its dependencies.

    <p>metadata</p> Signup and view all the answers

    Which command would you use to uninstall a package in npm?

    <p>npm uninstall package-name</p> Signup and view all the answers

    Who created npm?

    <p>Isaac Z. Schlueter</p> Signup and view all the answers

    Match the npm commands with their functions:

    <p>npm install package-name = Installs a package npm update = Updates installed packages npm list = Lists installed packages npm run script-name = Runs a script defined in package.json</p> Signup and view all the answers

    What file is considered the heart of any Node.js project?

    <p>package.json</p> Signup and view all the answers

    What command is used to create a new directory in the terminal?

    <p>mkdir</p> Signup and view all the answers

    The require function is used to export a function from a file in Node.js.

    <p>False</p> Signup and view all the answers

    What command is used to publish a package to npm?

    <p>npm publish</p> Signup and view all the answers

    To import a module in Node.js, you use the ______________ function.

    <p>require</p> Signup and view all the answers

    Match the following npm commands with their purposes:

    <p>npm init = Initialize a new Node.js project npm install = Install a third-party module npm login = Log into npm account npm publish = Publish package to npm</p> Signup and view all the answers

    Which of the following is a best practice for module development?

    <p>Use semantic versioning</p> Signup and view all the answers

    Documentation is unnecessary when writing modules for npm packages.

    <p>False</p> Signup and view all the answers

    What is the name of the directory where your custom module should be created?

    <p>my_module</p> Signup and view all the answers

    Which module is used for working with file and directory paths?

    <p>path</p> Signup and view all the answers

    The 'colors' package is a built-in module in Node.js.

    <p>False</p> Signup and view all the answers

    What is the main purpose of the 'fs' module in Node.js?

    <p>For file operations such as reading and writing files.</p> Signup and view all the answers

    To convert Celsius to Fahrenheit, you can use the formula ________.

    <p>(Celsius * 9/5) + 32</p> Signup and view all the answers

    Match the following Node.js modules with their functionality:

    <p>http = Creating HTTP servers crypto = Cryptographic functionality util = Utility functions os = Operating system-related operations</p> Signup and view all the answers

    Which of the following is NOT an important built-in module in Node.js?

    <p>express</p> Signup and view all the answers

    The 'child_process' module allows for spawning child processes.

    <p>True</p> Signup and view all the answers

    In the given code, which function is used to say goodbye?

    <p>sayGoodbye</p> Signup and view all the answers

    To create TCP servers and clients, you would use the ________ module.

    <p>net</p> Signup and view all the answers

    Which of the following methods is used to import local modules in Node.js?

    <p>require</p> Signup and view all the answers

    What does the 'version' field in package.json represent?

    <p>The current version of your project</p> Signup and view all the answers

    The 'devDependencies' section includes packages required for the application to run in production.

    <p>False</p> Signup and view all the answers

    What command is used to start the application defined in the scripts section?

    <p>npm start</p> Signup and view all the answers

    The version scheme that uses MAJOR.MINOR.PATCH is called _______.

    <p>Semantic Versioning</p> Signup and view all the answers

    What does the caret symbol (^) in version ranges indicate?

    <p>Compatible with this version and later, but before the next major version</p> Signup and view all the answers

    Match the following terms with their corresponding descriptions:

    <p>version = Current version of your project main = Entry point of the application scripts = Custom commands that can be executed with npm dependencies = Packages required for the application to run</p> Signup and view all the answers

    The command 'npm test' will execute the script defined as 'test' in the package.json.

    <p>True</p> Signup and view all the answers

    What is the purpose of the dependencies section in package.json?

    <p>To list packages required for the application to run.</p> Signup and view all the answers

    Study Notes

    Backend Development: NPM and Modules

    • Backend development course, week two, class one.
    • The course is focused on NPM (Node Package Manager) and modules.
    • A table of contents outlines the course structure.

    Node Package Manager (NPM)

    • NPM is the default package manager for Node.js.
    • It's a command-line tool.
    • It simplifies installing, updating, and managing third-party libraries and tools.
    • Created by Isaac Z. Schlueter in 2010.
    • Became the official package manager for Node.js in 2011.
    • Maintained by npm, Inc., a subsidiary of GitHub (owned by Microsoft).

    Basic NPM Commands

    • npm init: Initializes a new Node.js project.
    • npm install <package-name>: Installs a package and adds it to dependencies.
    • npm install <package-name>@<version>: Installs a specific version of a package.
    • npm install <package-name> --save-dev: Installs a package as a dev dependency.
    • npm uninstall <package-name>: Uninstalls a package.
    • npm update: Updates packages.
    • npm list: Lists installed packages.
    • npm run <script-name>: Runs a script defined in package.json.

    Understanding Package.json

    • The package.json file is the heart of any Node.js project.
    • It contains metadata about the project and lists its dependencies.
    • name: The name of your project.
    • version: The current version of your project.
    • description: A short description of your project.
    • main: The entry point of your application.
    • scripts: Custom scripts that can be run.
    • dependencies: Packages required for the application to run.
    • devDependencies: Packages only needed for development and testing.

    Understanding Package.json - SemVer

    • Semantic Versioning (SemVer) is a versioning scheme.
    • It uses a three-part version number: MAJOR.MINOR.PATCH.
    • MAJOR: Incompatible API changes.
    • MINOR: Add functionality (backwards-compatible).
    • PATCH: Bug fixes (backwards-compatible).
    • package.json allows specifying version ranges (e.g., ^, ~, *).

    Writing Your Own Package

    • Creating a new directory.
    • Initializing the new directory with npm init.
    • Writing your own modules.
    • Exporting and Importing (using require and module.exports).
    • Publishing package to NPM using npm login and npm publish.

    Best Practices for Module Development

    • Write clear and concise documentation.
    • Include examples in your README.md.
    • Use semantic versioning.
    • Keep your dependencies up-to-date.
    • Write tests for your module.
    • Utilize continuous integration (CI) tools.

    Importing and Using a Package

    • Importing different types of modules in Node.js (local, third-party, and custom).
    • Detailed steps and example are provided for creating a directory, initializing a project, installing a module, creating a file, and importing the file.

    Important Built-in Node.js Modules

    • The document includes a list of important built-in modules, e.g., path, http, util, crypto, os.

    Hands-on Assignment

    • The task involves creating an application that converts temperatures between Celsius and Fahrenheit.
    • Instructions specify creating index.js, converter.js, using variables and handling conversions using formulas.
    • Includes the formulas (converting Celsius to Fahrenheit and Fahrenheit to Celsius)
    • Emphasizes clear documentation and avoiding magic numbers.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Explore the fundamentals of NPM (Node Package Manager) and modules in this week two quiz of the backend development course. Learn essential commands for managing packages and build a solid foundation for your Node.js projects. Test your knowledge with key concepts and practices crucial for effective backend development.

    More Like This

    Node.js Overview and Key Features Quiz
    12 questions
    New Public Management (NPM) Quiz
    8 questions
    New Public Management (NPM) Principles
    8 questions
    Understanding package.json in Node.js
    5 questions
    Use Quizgecko on...
    Browser
    Browser