Menu

Node.js Basics

February 3, 2018 - javascript, Node.js

Create a node module

new-module.js

exports.myText = 'Hi from the module';

module-demo.js

var myModule = require('./new-module');
console.log(myModule.myText);

Run the file

node module-demo.js
// Expected Output
// Hi from the module

Create a package.json

npm init
#or
npm init --yes

Install all packages from predefined package.json

npm install

## Install nodemon package and run it

Installation

npm install -g nodemon

Run the app

nodemon index.js

If index.js is changed and saved nodemon restarts the server.

Install lodash

npm install lodash

index.js

var _ = require('lodash');
console.log(_.random(1,100));
Tags: ,