"Easy" is highly subjective. If you're proficient at picking up new architecture paradigms for familiar languages, you're adept with ESM syntax, and refactoring is a skill; then you might consider it easy.
It's a paradigm shift, so there's always going to be some friction in migration. For your express needs, check out Oak https://deno.land/x/oak@v9.0.0
I wouldn't call it a paradigm shift in terms of the code itself. The main thing is that it's a completely different set of system APIs that have to be targeted (by you or by the libraries you use). That means a lot of changes wherever those are involved, but they should mostly be straightforward changes (of course YMMV if you're having to use a new library/framework instead of just the new system APIs)
This is my first day obviously, but what I can see are the following interesting syntax, bare server.
const server = Deno.listen({ port: 8080 });
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
// Connections to the server will be yielded up as an async iterable.
for await (const conn of server) {
// In order to not be blocking, we need to handle each connection individually
// without awaiting the
function
serveHttp(conn);
}
async function serveHttp(conn: Deno.Conn) {
// This "upgrades" a network connection into an HTTP connection.
const httpConn = Deno.serveHttp(conn);
// Each request sent over the HTTP connection will be yielded as an async
// iterator from the HTTP connection.
for await (const requestEvent of httpConn) {
// The native HTTP server uses the web standard `Request` and `Response`
// objects.
const body = `Your user-agent is:\n\n${requestEvent.request.headers.get(
"user-agent",
) ?? "Unknown"}`;
// The requestEvent's `.respondWith()` method is how we send the response
// back to the client.
requestEvent.respondWith(
new Response(body, {
status: 200,
}),
);
}
}
Everything async await. There is an option to use a library, but it's to be deprecated,the native option is stable.
Interesting import code:
import { serve } from "https://deno.land/std@0.105.0/http/server.ts";
So, Deno supports typescript out of the box or just plain JS.
Deno doesn't support npm packages, imports are done via url.
There is a window object, for whatever that's supposed to be used.
Runs sandboxed, access to filesystem etc runs on permission basis.
Access to the browser API without installing anything else.
Packages are cached, this was very annoying in nodeJS.
package management, scripts are quite the shift in Deno. there are tools like velociraptor and trex which help bridge the gap, but there's still a lot to learn that's much different than node-world.
Comments
"Easy" is highly subjective. If you're proficient at picking up new architecture paradigms for familiar languages, you're adept with ESM syntax, and refactoring is a skill; then you might consider it easy.
It's a paradigm shift, so there's always going to be some friction in migration. For your express needs, check out Oak https://deno.land/x/oak@v9.0.0
I wouldn't call it a paradigm shift in terms of the code itself. The main thing is that it's a completely different set of system APIs that have to be targeted (by you or by the libraries you use). That means a lot of changes wherever those are involved, but they should mostly be straightforward changes (of course YMMV if you're having to use a new library/framework instead of just the new system APIs)
Could you clarify what is the paradigm shift? Static types? (If so I agree, but using Node does not imply not using TS)
This is my first day obviously, but what I can see are the following interesting syntax, bare server.
} }Everything async await. There is an option to use a library, but it's to be deprecated,the native option is stable. Interesting import code:
So, Deno supports typescript out of the box or just plain JS. Deno doesn't support npm packages, imports are done via url. There is a window object, for whatever that's supposed to be used. Runs sandboxed, access to filesystem etc runs on permission basis. Access to the browser API without installing anything else. Packages are cached, this was very annoying in nodeJS.Sounds and looks pretty damn good.
Probably more the removal of nodejs apis in favour of browser apis. For everything. (modules/imports included).
package management, scripts are quite the shift in Deno. there are tools like velociraptor and trex which help bridge the gap, but there's still a lot to learn that's much different than node-world.