Changes between Version 1 and Version 2 of Nodejs


Ignore:
Timestamp:
11/10/22 07:12:15 (2 years ago)
Author:
krit
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Nodejs

    v1 v2  
    33 * ref[https://nodejs.org/en/docs/guides/nodejs-docker-webapp/ here]
    44
    5 Create nodejs web app
     51. First, create a new directory where all the files would live. In this directory create a package.json file that describes your app and its dependencies: file package.json as following
     6{{{
     7{
     8  "name": "docker_web_app",
     9  "version": "1.0.0",
     10  "description": "Node.js on Docker",
     11  "author": "First Last <first.last@example.com>",
     12  "main": "server.js",
     13  "scripts": {
     14    "start": "node server.js"
     15  },
     16  "dependencies": {
     17    "express": "^4.16.1"
     18  }
     19}
     20}}}
     21With your new package.json file, run npm install. If you are using npm version 5 or later, this will generate a package-lock.json file which will be copied to your Docker image.
     22
     232. Then, create a server.js file that defines a web app using the Express.js framework:
     24
     25{{{
     26'use strict';
     27
     28const express = require('express');
     29
     30// Constants
     31const PORT = 8080;
     32const HOST = '0.0.0.0';
     33
     34// App
     35const app = express();
     36app.get('/', (req, res) => {
     37  res.send('Hello World');
     38});
     39
     40app.listen(PORT, HOST, () => {
     41  console.log(`Running on http://${HOST}:${PORT}`);
     42});
     43}}}
     44
     45