Generating only backend in sails.js - javascript

I am building an Sails.js app which would potentially have a single frontend worker and lots of backend workers.
These backend workers would not answer requests - they would process data for themselves, and store it for consumption by the frontend.
Is it possible to sails new an app without all the frontend scaffolding?

Yes, you have to use the command --no-frontend, for example:
sails new project --no-frontend
This will generate a project without the frontend scaffolding.

Related

how to store data in vercel as a json object and consume it in react app as an API like we do for the case of firebase?

I have a requirement where i need to send GET and POST requests to vercel to store and retrieve the data like we do in case of firebase in the form of JSON object.If vercel doesn't offer this is there any alternative platform to perform this.
Vercel is a platform for frontend hosting, not for full stack web applications. If you want to deploy a full stack application using Vercel you could use Vercel for your front-end and use some kind of cloud service to persist and fetch your data like MongoDB Atlas.
To access the cloud service where you are storing your data you could use serverless functions that are provided by Vercel.

registering socket IO to vite for sveltekit

I have written a few apps using svelte and sapper and thought I would give sveltekit a go.
All in all it works, but I am now running into the issue of registering a worker on ther server.
Basically I am trying to add socket.io to my app because I want to be able to send and receive data from the server. With sapper this wasn't really an issue because you had the server.js file where you could connect socket.io to the polka/express server. But I cannot find any equivalent in sveltekit and vite.
I experimented a bit and I can create a new socket.io server in a route, but that will lead to a bunch of new problems, such as it being on a separate port and causing cors issues.
So I am wondering is this possible with sveltekit and how do you get access to the underlying server?
The #sveltejs/adapter-node also builds express/polka compatible middleware which is exposed as build/middelwares.js which you can import into a custom /server.cjs:
const {
assetsMiddleware,
prerenderedMiddleware,
kitMiddleware,
} = require("./build/middlewares.js");
...
app.use(assetsMiddleware, prerenderedMiddleware, kitMiddleware);
The node adaptor also has an entryPoint option, which allows bundling the custom server into the build, but I ran into issues using this approach.
Adapters are not used during development (aka npx svelte-kit dev).
But using the svelte.config.js you're able to inject socket.io into the vite server:
...
kit: {
...
vite: {
plugins: [
{
name: "sveltekit-socket-io",
configureServer(server) {
const io = new Server(server.httpServer);
...
},
},
],
},
},
Note: the dev server needs to be restarted to apply changes in the server code.
You could use entr to automate that.
You cannot connect to a polka/express server because depending on the adapter you choose there can be no polka/express server used - if you deploy to a serverless platform for example. Sockets for serverless are not so easy to implement and their implementation depend on the provider.
You are raising an important concern but right now I'm afraid this is not possible - someone corrects me if I'm wrong.
What you still can do is to write your front with SvelteKit, build it as a static/SPA/node application and then use your build from your own polka/express server. You lose the swift development experience offered by SvelteKit though, since your development will be parted in two: first the client, then the server.
EDIT
You can also use a data-pusher third service. They are straightforward to use but not necessarily free. Here is a list of data-pusher services from the Vercel page:
Ably
Pusher
PubNub
Firebase Realtime Database
TalkJS
SendBird
Supabase

How to implement Socket.io with next.js without separate node server

I want to build a chat system with Next.js. I am not sure how I have to setup the socket server.
I want this to implement Next server not with a separate server.
Should I have to make a server.js file in root and run a server?
You will need to create custom server however, then you can't deploy to vercel, and you got yourself a regular nodejs application.
You could use cloud providers to handle sockets for you, or as you said, you could split your application to a regular next.js app and deploy your socket application separately.

Host static HTML in Azure Web App Service

I'm azure beginner
I've created nodejs service and deployed it to Azure Web App service, it works as expected.
So, I have resource group mars-app and existing Web App service application my-mars-web-app.
Now, I want to add static HTML file, to show it when user goes to root URL https://***.azurewebsites.net/
To achieve it,
I have cloned github repo with client side to azure storage with azure cli help
In cliend code folder, I have tried to run az webapp up -g mars-app -n my-mars-web-app --html, but every time I'm receiving:
The webapp my-mars-web-app is a Linux app. The code detected at '/home/serhii/azure-website' will default to '<module 'os' from '/opt/az/lib/python3.6/os.py'>'. Please create a new app to continue this operation.
Because of above error, I have added index.html to dist diretory in my backend app
app.get('/', function (req, res) {
res.sendfile('dist/index.html');
});
and it works. But I'm not sure it is a good solution
What the best practice to add static HTML files to existing Web App service?
This question may be a dublicate of this question, but it was asked 5 years ago, so maybe something changed.
P.S. I know about Static Web Apps, but it is in preview and I'm interested in more generic solutions.
Thanks in advance
[UPDATE]
Here an article about deploying react app
Why you want to add static HTML files to existing web app services, for update or others?
In my opinon, now that you have used git, you can use continuous deployment.
When you modify your program (add new or modify files), in the Action of github, you will see the program start to deploy again. This should be the best deployment plan.

how to add React component with Postgres database

I have a doubt, suppose, I made a React project using npx create-my-app myProject
and in this public folder, I have several folders having NodeJS for Postgres database.
so, my question is if I have to load data from postgres to react component, how will I do it? can I do it using axios? if not then how?
if yes, how will I test it? suppose, my backend nodejs postgres is online, and I am using my react on local:3000, how will I test it, if postgres has get function is like /api/xyz
?
You really should not do this in the Frontend (=React) part of you application.
This would open the door to some serious security issues, as you would have to establish a connection to the database from the client, and in order do so, have to save the databases credentials there. It would be relatively easy for any attacker to get this data.
Basically, create a backend server (maybe with nodejs), create a connection there to postgres, fetch the requested data there and send it to the client. You can use axios for that or any other http library like fetch. Your frontend can run on localhost:3000 and the backend on localhost:4000. Here is a tutorial you can follow.

Categories