File server built with node, express in typescript.
Create file named .env.dev
under folder env
in the root directory with the following content.
PORT=5000
ROOT_DIR='.'
REQUEST_DELAY=0
Run script.
npm run dev
A configuration file named env.config.ts
will be created in .src/config
and server will be listening to the given port.
-
- Create environment file for other scenarios in
env
folder, eg, stage, prod, etc.
- Create environment file for other scenarios in
-
- Add one new command in
package.json
with change theNODE_ENV
value, eg.
- Add one new command in
"stage": "NODE_ENV=stage npm run start-config && nodemon ./src/server.ts --ignore ./uploads",
Go to project file-server-angular
, build Angular application for production.
npm run prod
Go to project file-server-node
, build node server for production.
npm run prod
Then, copy all frontend files in file-server-angular/dist
to file-server-node/dist/wwww
.
Copy all backend and frontend files to server.
cd 'file-server-node'
node './dist/src/server.js'
Access http://192.168.0.2:12020/
.
Find the server process by searching 'node'.
ps aux | grep node
Johnny 3761 0.0 3.2 899840 58356 ? Ssl 07:32 0:03 node ./dist/src/server.js
Kill it with PID.
kill -9 3761
Build for production. All the compiled html files and js files will be generated in dist
.
npm run build
Create image with node.js.
docker build -t jojozhuang/file-server-node .
Create container.
docker run --name file-server -p 12020:80 -v=/var/services/video:/app/root -v=/var/services/web/fullstack-sites/file-server/www:/app/web -d jojozhuang/file-server-node
Access http://192.168.0.2:12020/ in browser.