Coder Social home page Coder Social logo

darnley / ng-express Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 714 KB

Basic ready for production Angular application with ExpressJs server render

License: MIT License

JavaScript 32.86% TypeScript 51.97% HTML 10.15% CSS 0.56% Dockerfile 4.46%
angular expressjs docker ready-to-use

ng-express's Introduction

NgExpress

Basic ready for production Angular application with ExpressJs server render

Installation

Use the package manager npm to install NgExpress.

It is not a installable package. You must download it in a ZIP file and unpack in your favorite folder.

Usage

Development environment

First of all, rename the .env.example file to .env. It will be used as an application configuration file. In the production environment, you are supposed to overwrite those configurations.

In development environment you can just run the following command in NgExpress root folder. It will install all the dependencies for NgExpress and the Angular application inside /app folder.

$ npm install

If you would like to run the application watching its changes, just run the following command. It will also run npm install.

$ npm start

Production environment

This package is ready for Docker. If you build the image and run the container, the application is ready for usage.

If you would like to publish the code yourself, just run the following command in the application's root folder.

$ npm run prod

It will compile the Angular application into /dist folder in production mode. After that, you are free to delete /app folder in production environment to reduce disk usage.

After compiling your Angular application, change the NODE_ENV in your environment variables or in .env file to production. It will enable the application caching (in cache.js file).

Last of all, execute the application using you Node.js runtime.

$ node ./index.js

The Dockerfile uses PM2 to manage the Node.js process. You are free to use another process manager.

Using Dockerfile

First of all, you should build your Docker image. In a command prompt of your choice, run the following command to create an image. The -t flag lets you tag your image so it's easier to find later using the docker images command.

$ docker build -t <your namespace>/<your application name> .

Your image will now be listed by Docker.

$ docker images

# Example
REPOSITORY                                  TAG        ID              CREATED
node                                        10         1934b0b038d1    5 days ago
<your namespace>/<your application name>    latest     d64d3505b0d2    1 minute ago

Running your image with -d runs the container in detached mode, leaving the container running in the background. The -p flag redirects a public port to a private port inside the container. Run the image you previously built.

$ docker run -p 49160:3000 -d <your namespace>/<your application name>

The 49160 is the host port which will forward the traffic to port 3000 in Docker machine. In this example, just access http://localhost:49160 through your favorite browser. You are free to change this port.

Using another Angular application

This package is delivered with a standard and basic Angular application. If you would like to use your already existent Angular application, just follow these steps:

  • Remove all the files from /app folder
  • Copy your existent Angular application or create a new one in /app folder

You must have @angular/cli globally installed, otherwise you should modify the scripts in the package.json file.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

ng-express's People

Watchers

James Cloos 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.