Create a build for Node.js (fastify) server to electron app - node.js

I am using node js 10.15.0 along with fastify server int it.
I am also using normal public folder shared in the project.
Below is the project hierarchy.
NOTE: This code when started, starts as a standalone server which also servers UI.
I tried electron-packager/ electron-builder but I am not getting desired build as executable like .exe etc.
Question:
Can anyone please guide me through how can I achieve creating a build from node.js pure server code using fastify.

Related

Debugging not working in Intellij - NodeJS + NestJS App

I am trying to debug a nodejs + nest application in IntelliJ, I am able to start the application using two types of configs.
Using Yarn (through NPM configuration template in intellij)
Using Node (I am not sure but when I use the main.js from dist folder then I get some debug point but it is useless as it is not pointing to my actual code base)
Debugger doesn't work for any of the above options!
I am posting screen shots of both the configurations.
New to Node + IntelliJ, so not sure what did I do wrong in both the configurations! Any help would be appreciated.
Intellij Version is 2020.3.3 And NodeJS application exposes several APIs, I am trying to call the APIs using a Postman and expect it to debug.
Debugging in both main.ts and controllers works for me when using the configuration below:
See also https://github.com/nestjs/nest/issues/993 for some recipes

How to 'build' a node js application?

I have a node.js application that run as a application server.
It is deployed on an Ubuntu 20.04 machine running on AWS, uses nginx as a reverse proxy and PM2 as a service starter.
Everything seems perfectly configured.
What looks strange to me, is that I have a React application, in a similar environment, but, before to move it on the server, I run build it, so creating a sort of packed and not easily human readable application.
My question is: Is there the need to do the same with a node.js application?
And, in case of positive answer, How to 'build' a node.js application?
There is no need to build a normal nodejs application.
What you mean is the use of a bundler e.g. webpack and a javascript compiler e.g. babel. To create a react application, you usually use a tool like create-react-app that sets up all this stuff for you. For react you need the compilation beacause you use the jsx syntax that browsers do not understand. In addition to that a bundler has some more advantages.
Check out this video if you want to know more about it:
https://www.youtube.com/watch?v=5IG4UmULyoA
No you don't have to build anything for node.js you just have to run the server. for client side apps you need to build and serve the Dist through web servers like apache or nginx.

How to run separate node server in electron app

I'm building an Electron app using React.
I couldn't get the native node module "printer" to work in electron. There were problems while rebuilding native node module. I need the list of printers that are connected to the device in my app. Then print text using specific printer.
So I decided to run an express server separate from electron. Express app needs to have its own node_modules and package.json. And client side will connect the local node server via http request to localhost.
Is it possible to do so? How can I add express app to the dist folder which is created by electron-builder and make it run when electron app is launched?
There is already a way to way the native printing functionality in electron.
Please follow the below link.
https://www.electronjs.org/docs/api/web-contents#contentsgetprinters

Integrating Angular2 with Nodejs

I'm building a Nodejs + Angular2 project for the first time and stuck with architecture design issue.
There are following possibilities:
Develop Angular2 project separately, build and copy the files into Nodejs project
Develop Angular2 project from within Nodejs project (say from public folder)
Run two servers for Angular2 as frontend and Nodejs as backend (how to do this in shared hosting then? AWS is fine)
Using yeoman for creating projects for both Angular2 and Nodejs.
Which is the best option?
Any other idea?
2 is basically the solution. The work flow goes like this:
Start Angular Development Server.
Start NodeJS server.
Once you are ready to go live:
- Compile Angular and build out into a public folder using ng build. This folder will be accessible to the public and holds html files, javascript files, etc.
- Then, you use Nodejs to direct clients to those html files. When you use NodeJS or any other backend, this is typically how you will serve the Angular 2 files. It is also possible to develop Angular 2 SERVER SIDE instead, however, this is a bit harder and I wouldn't recommend it unless working with another framework entirely. Here is a really great tutorial that walks you through it:
https://scotch.io/tutorials/mean-app-with-angular-2-and-the-angular-cli

Node-Webkit and AngularJS package apps: require not defined

I am using https://github.com/mllrsohn/grunt-node-webkit-builder to package my node-webkit app which is built using AngularJS.
The app works fine on MAC when I build from Sublime Text. But when I package the app using any packaging tool, I get the error saying "require is not defined". What am I missing?
For more context, I have a services layer which is written in Node.js using express. The Angular project calls Node.js APIs and renders the content. I am using a SQLite3 DB. Which is the best way to package such apps? I am alright with writing an installer starts Node.js server separately.
You'll always get a "require is not defined" error if you don't use a node-webkit environement for developpement in Windows. You can use nodebob for developpement environement :
You have to put your html files into nodebob\buildTools\nw and then run nw.exe
Just reload it after your changes

Resources