{"id":15686445,"url":"https://github.com/jaychase/ngx-express-universal","last_synced_at":"2025-07-24T18:17:30.528Z","repository":{"id":72262484,"uuid":"99997649","full_name":"JayChase/ngx-express-universal","owner":"JayChase","description":"angular-cli  app with universal","archived":false,"fork":false,"pushed_at":"2017-09-15T07:49:16.000Z","size":115,"stargazers_count":9,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-10T03:06:40.694Z","etag":null,"topics":["angular","angular-cli","express","pre-rendering","seo-friendly","server-side-rendering","universal"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JayChase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-11T06:13:40.000Z","updated_at":"2018-07-20T12:00:18.000Z","dependencies_parsed_at":"2023-03-30T12:35:20.150Z","dependency_job_id":null,"html_url":"https://github.com/JayChase/ngx-express-universal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JayChase/ngx-express-universal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayChase%2Fngx-express-universal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayChase%2Fngx-express-universal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayChase%2Fngx-express-universal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayChase%2Fngx-express-universal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JayChase","download_url":"https://codeload.github.com/JayChase/ngx-express-universal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayChase%2Fngx-express-universal/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266886031,"owners_count":24001046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular-cli","express","pre-rendering","seo-friendly","server-side-rendering","universal"],"created_at":"2024-10-03T17:40:20.792Z","updated_at":"2025-07-24T18:17:30.502Z","avatar_url":"https://github.com/JayChase.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NgxExpressUniversal\n\nAngular Cli (1.30) + Angular Material 2 + Angular Universal.\n\nThis is a rough guide of how to get up and running with all of the above. A blog post to accompany the code can be found [here](https://www.usefuldev.com/blog/post/angular-cli-with-material-2-and-universal). The starting point is an Angular-cli generated app with Material 2 added. The aim of this repo is to be a guide to the minimum steps required to get everything up and running so production concerns like error handling, caching and performance etc... are not covered (but hopefully will be in a separate repo with all the best practices later).\n\n### quick links\nTo get started with [Angular cli](https://github.com/angular/angular-cli),\nto install [Angular Material2](https://github.com/angular/material2/blob/master/guides/getting-started.md),\nand to install [Angular Universal](https://github.com/angular/angular-cli/wiki/stories-universal-rendering).\n\n## getting started with the sample\n\n```bash\ngit clone https://github.com/JayChase/ngx-express-universal.git\ncd ngx-express-universal\nnpm install\nnpm run build-all\nnpm run server\n```\n\n## steps to create the project\n\n### add universal\n\nThese steps are just a checklist for the [Angular cli story](https://github.com/angular/angular-cli) so use that for full details.\n\n* install @angular/platform-server (--save-dev)\n* add src/tsconfig.server.json\n* add src/main.server.ts\n* add src/app.server.module.ts\n* change src/app.module.ts\n\n```typescript\nBrowserModule.withServerTransition({\n      appId: 'cli-uni'\n    })\n```\n\n* add server app to .angular-cli.json\n\n```json\napps: [\n  ...,\n   {\n      \"name\": \"uni\",\n      \"platform\": \"server\",\n      \"root\": \"src\",\n      \"outDir\": \"dist-server\",\n      \"assets\": [\n        \"assets\",\n        \"favicon.ico\"\n      ],\n      \"index\": \"index.html\",\n      \"main\": \"main.server.ts\",\n      \"test\": \"test.ts\",\n      \"tsconfig\": \"tsconfig.server.json\",\n      \"testTsconfig\": \"tsconfig.spec.json\",\n      \"prefix\": \"app\",\n      \"styles\": [\n        \"styles.css\"\n      ],\n      \"scripts\": [],\n      \"environmentSource\": \"environments/environment.ts\",\n      \"environments\": {\n        \"dev\": \"environments/environment.ts\",\n        \"prod\": \"environments/environment.prod.ts\"\n      }\n    }\n]\n```\n\n* exclude dist-server in .gitignore \n\n### add an express server\n\n* install express @types/node @types/express (--save)\n* add server-src/tsconfig.json (standard node.js tsconfig with output path set to ../server)\n* add build-server script to package.json\n* add server-src/server.ts\n\n```typescript\nrequire('zone.js/dist/zone-node');\nconst renderModuleFactory = require('@angular/platform-server').renderModuleFactory;\nconst AppServerModuleNgFactory = require('../dist-server/main.d8532c2d5f13c00de031.bundle.js').AppServerModuleNgFactory; // bundle name set by npm script build-set-server-main-bundle\n// const index = require('fs').readFileSync('./dist-server/index.html', 'utf8'); // for server side rendering\nconst index = require('fs').readFileSync('./dist/index.html', 'utf8'); // for server to client transition\nconst express = require('express');\nconst path = require('path');\nconst app = express();\nconst port = process.env.port || 3000;\n\napp.use(express.static(path.join(__dirname, '../dist'), {\n    index: false\n}));\n\napp.use('*', function (req, res, next) {\n    // res.sendFile(path.join(__dirname,'../dist/index.html'));\n    renderModuleFactory(\n        AppServerModuleNgFactory, { document: index, url: req.baseUrl }).then(html =\u003e {\n            res.send(html);\n        });\n});\n\napp.listen(port, function () {\n    console.log('listening on port: ' + port);\n});\n```\n\n```json\n\"build-server\": \"tsc -p ./server-src/tsconfig.json\"\n```\n\n### fix missing css bundle (for server side rendering)\n\nTo get the Material styles working on the server side add the style bundle to the server index.html.\n\n* install glob and @types/glob (--save-dev)\n* add build/addStyleBundle.js\n* add build-uni-add-css to package.json\n\n```json\n\"build-uni-add-css\": \"node build/addStyleBundle\"\n```\n\n* add \u003c!--css-bundle--\u003e to src/index.html\n* change server/server.ts to use dist-server/index.html\n\n```typescript\nconst index = require('fs').readFileSync('./dist/index.html', 'utf8'); \n```\n\n### update server.ts with main.*.js bundle name on build\n\n* add build/setServerMainBundle.js\n* add build-set-server-main-bundle\n\n```json\n\"build-set-server-main-bundle\": \"node build/setServerMainBundle\"\n```\n\n### chosing between server side render or server to client transition\n\nJust switch between the server or app index.html. So for server side the index in server.ts should be:\n\n```typescript\nconst index = require('fs').readFileSync('./dist-server/index.html', 'utf8');\n```\n\nand for server client transition\n\n```typescript\nconst index = require('fs').readFileSync('./dist/index.html', 'utf8');\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaychase%2Fngx-express-universal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaychase%2Fngx-express-universal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaychase%2Fngx-express-universal/lists"}