How to create a sample application
- Create a folder with any name in your workspace, for example like helloworld
- Go to command and navigate to the folder you have created.
- Execute the below command to create the default package structure for you. Provide package name, description etc when prompted.
npm init
- You can install the dependent modules by using below command.For example, we are installing express framework which will help you to develop applications with robust set of features.
npm i express`
- Execute the below command to open the package.json in code.
code package.json
- Now, create index.js and write your sample code like below.
const express = require('express');
const server = express();
// above two lines is to use express framework
server.get('/', (req, res) => {
res.send('Hello World!!');
});
server.listen(5000,()=>console.log('server started on 5000'));
How to run the above code
- Execute the below command in the terminal and ensure you are in the project directory.
node index.js
- Go to browser, and hit http://localhost:5000/ path. You must see
Hello world!!
message in case of no errors.