Giter Club home page Giter Club logo

nodescript's Introduction

STEP 1: ADD REQUIRED REPO FROM OFFICIAL NODEJS WEBSITE.

curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -

STEP 2: INSTALL NODEJS.

sudo yum install -y nodejs

STEP 3: VERIFY INSTALLED VERSION.

node -v
npm -v

STEP 4: CREATE A server.js FILE AND RUN IT.

Create a file named server.js with the provided the below content.

const http = require('http');
const fs = require('fs');
const path = require('path');

const server = http.createServer((req, res) => {
  const filePath = path.join(__dirname, 'index.html');
  const stat = fs.statSync(filePath);

  res.writeHead(200, {
    'Content-Type': 'text/html',
    'Content-Length': stat.size,
  });

  const readStream = fs.createReadStream(filePath);
  readStream.pipe(res);
});

const PORT = 80;
server.listen(PORT, () => {
  console.log(`Server is running on http://localhost:${PORT}`);
});

this script creates a basic web server that listens on port 80, reads the content of an index.html file, and sends it as the response when a request is made to the server. The server logs a message indicating that it is running on http://localhost:80.

STEP 5: INSTALL REQUIRED PACKAGES / INSTALL DEPENDENCIES.

npm install

STEP 6: NODE.JS WILL INTERPRET AND EXECUTE THE CODE IN THE server.js FILE. THIS IS A COMMON PATTERN FOR RUNNING SERVER-SIDE JAVASCRIPT APPLICATIONS.

node server.js

After following these steps, your Node.js server should be up and running.

Make sure your ec2 instance security group io opened with required port i.e; 80/3000/any toher port

========================================================================================================================

PM2 useful Commands

Command to install pm2

npm install -g pm2

list all running processes/apps.

pm2 list   (or) pm ls

Start app/services with name

pm2 start server.js --name "my-app1"

Command to list the logs

pm2 logs id/name

ex: pm2

Command to Monitor the resources

pm2 monit

To make service as startup

pm2 startup

Command to delete service/app

pm2 delete name/id

nodescript's People

Contributors

avizway1 avatar

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.