DEV Community

Cover image for Check your Nodes?
kymiddleton
kymiddleton

Posted on

Check your Nodes?

Node.js is an open-source, cross-platform JavaScript runtime environment designed to let JavaScript run outside of the browser or webpage. It’s a general utility that can be used for a variety of purposes including asset compilation, scripting, monitoring, creating desktop applications, and most notably as the basis for web servers. JavaScript can be used for the server side since Node reuses JavaScript. This means a front-end developer can build an entire server themselves. Other benefits of node:

  • Numerous plugins are available which easily expands its capabilities.
  • Creating an entire working server can be accomplished with few lines of code which allows for faster implementations.
  • The single-threaded asynchronous model allows handling of multiples requests simultaneously without bottlenecks or slowed performance.

SETTING UP A NODE PROJECT
QUICK REFERENCE GUIDE

  • Open Favorite Code Editor
  • Open Command Line within Code Editor
`mkdir <projectName>`
`cd <projectName>`
  • Install the Node Packages in the root directory of the project folder using the following command:
`npm init`

This step will initialize the folder and create the package.json file.

  • Once the installation has completed the program will prompt a series of questions to gather contextual information about the project such the project name , copyright, version, description, entry point file name, author, etc.
  • Completion of the fields is not required and can be skipped by using the enter key.
  • When prompted with Is this okay? (yes) respond by entering yes followed by the enter key.

  • Look inside the folder for the package.json file.

  • Open the file to review and familiarize contents.

  • The syntax of the JSON folder is a JavaScript object.

  • Next, run the following command in the same directory of the root folder:

`npm install express`

This will create the node_modules subfolder.

  • The node_modules file holds all the modules for the particular project.

  • Go back and look inside the package.json file

    • A new object will appear, dependencies, which should have Express listed.
    • Any new dependencies will be added to the package.json file.

Steps to Take for Existing Projects:
When working on an existing project that already contains a package.json file run the following command:

`npm install`

This will evaluate the contents of the package.json file and install additional packages if needed.

Steps to Take when Receiving an Existing Project:

`npm install`

This will evaluate the contents of the package.json file and install additional packages if needed.

Do NOT Share the Node Modules Folder

This is a critical step to remember especially when collaborating on projects.

  • Node Module folders must NOT be shared, ever.
  • When the npm install command runs it compiles files based on the needs of the specific computer.
  • When collaborating or sharing project files, other contributors will need to install the command npm install in the root directory of the project folder on THEIR computer.
  • Remember the npm install command without a package name evaluates the existing dependencies within the package.json file and installs needed dependencies.

With so many little steps to remember when building a full stack application I hope this guide becomes a helpful tool for others too.

Top comments (2)

Collapse
 
chromadream profile image
Jonathan Nicholas

Honestly, I would recommend using Yarn more this year, simply because npm historically had some critical bugs. However, npm is installed together with Node, so it's kinda hard not to recommend it.

Collapse
 
kymiddleton profile image
kymiddleton

Thanks for the feedback. I haven't been exposed to Yarn yet so I'll certainly take a look.