投稿時間:2023-06-04 22:17:27 RSSフィード2023-06-04 22:00 分まとめ(18件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita 文書から正確な情報をプロンプトに入れて応答をするChatGPTのBotのミニマムな実装 https://qiita.com/hotekagi/items/829bb3a50f3014ddad50 chatgpt 2023-06-04 21:39:51
python Pythonタグが付けられた新着投稿 - Qiita pythonでMIDIが再生できないときにやったこと https://qiita.com/zakuzakuzaki/items/2720d916c6971164f173 timidity 2023-06-04 21:28:34
python Pythonタグが付けられた新着投稿 - Qiita ラズパイでスマートリモコンを作ってみた https://qiita.com/hexanitrobenzen/items/c27a8572c1138f900df6 作ってみた 2023-06-04 21:23:02
python Pythonタグが付けられた新着投稿 - Qiita pyenvの使い方 https://qiita.com/WhiteCat6142/items/a9f2cc797186ba0fc192 gitclonepyenvzsh 2023-06-04 21:04:11
js JavaScriptタグが付けられた新着投稿 - Qiita Promise、async/await https://qiita.com/AraiShg17/items/43ae67c133512ae0f7f1 asyncawait 2023-06-04 21:12:50
AWS AWSタグが付けられた新着投稿 - Qiita Terraformを単品で使うのではなく、GitLabと一緒に使う方法 https://qiita.com/Hurry_Fox/items/6ba96f7bf5f4aad0e482 gitlab 2023-06-04 21:08:55
Docker dockerタグが付けられた新着投稿 - Qiita 『Django4 Web アプリ開発実装ハンドブック』のサインアップページでアドレス入力欄がでなかった話 https://qiita.com/goto2023/items/056e2349f5c15e1beefd django 2023-06-04 21:01:49
GCP gcpタグが付けられた新着投稿 - Qiita Terraformを単品で使うのではなく、GitLabと一緒に使う方法 https://qiita.com/Hurry_Fox/items/6ba96f7bf5f4aad0e482 gitlab 2023-06-04 21:08:55
Azure Azureタグが付けられた新着投稿 - Qiita Terraformを単品で使うのではなく、GitLabと一緒に使う方法 https://qiita.com/Hurry_Fox/items/6ba96f7bf5f4aad0e482 gitlab 2023-06-04 21:08:55
技術ブログ Developers.IO クラスメソッド データアナリティクス通信(AWSデータ分析編) – 2023年6月号 https://dev.classmethod.jp/articles/cm-da-news-analytics-202306/ 関連 2023-06-04 12:47:49
海外TECH MakeUseOf How to Troubleshoot Your 3D Printer With a 3D Benchy https://www.makeuseof.com/troubleshoot-3d-printer-with-3d-benchy/ stress 2023-06-04 12:30:18
海外TECH DEV Community Authentication system using Golang and Sveltekit - Frontend user registration and activation https://dev.to/sirneij/authentication-system-using-golang-and-sveltekit-frontend-user-registration-and-activation-4104 Authentication system using Golang and Sveltekit Frontend user registration and activation IntroductionI think it is great for us to see in action the backend code we ve been writing This intermittent switch tends to refresh me as I will focus on writing a different set of languages and doing something more of aesthetics than extreme logic If you have a different opinion kindly drop it in the comment section We will build out the user registration and activation pages in this article Before then we will provide the frontend URL for the backend since it s needed to correctly construct the email Source codeThe source code for this series is hosted on GitHub via Sirneij go auth A fullstack session based authentication system using golang and sveltekit go auth View on GitHub Implementation Step Set the frontend URL in the backendWe need to provide the base URL of a front end application since our backend needs it As usual we ll set FRONTEND URL in our env file and load it into our app s config type cmd api config go func updateConfigWithEnvVariables config error Frontend URL flag StringVar amp cfg frontendURL frontend url os Getenv FRONTEND URL Frontend URL We then add frontendURL to the config type in cmd api main go cmd api main go type config struct frontendURL string With that let s build the front end Step CSS and layoutWe will not delve into explaining the CSS of the code but we need to be aware that there is a styles css file in frontend src lib css folder If you followed the previous series you might know why we put our files in the lib folder With its help files in it can be imported via the lib alias It will contain library code utilities and components Next we will create a frontend src routes layout svelte lt script gt import Footer from lib components Footer svelte import Header from lib components Header svelte import Transition from lib components Transition svelte import lib css styles min css type import types PageData export let data lt script gt lt Transition key data url duration gt lt Header gt lt slot gt lt Footer gt lt Transition gt It s pretty simple We imported some components Footer Header and Transition We also needed some data for the page url This is needed for the Transition component lt frontend src lib components Transition svelte gt lt script gt import slide from svelte transition type string export let key type number export let duration lt script gt key key lt div in slide duration delay duration out slide duration gt lt slot gt lt div gt key url is used as a key because it needs to be unique We utilized Svelte s nifty transition package to provide a good page transition Next is Header lt frontend src lib components Header svelte gt lt script gt import page from app stores import Developer from lib img hero image png lt script gt lt header class header gt lt div class header container gt lt div class header left gt lt div class header crafted by container gt lt a href gt lt span gt Developed by lt span gt lt img src Developer alt John Owolabi Idogun gt lt a gt lt div gt lt div gt lt div class header right gt lt div class header nav item class active page url pathname gt lt a href gt home lt a gt lt div gt lt div class header nav item class active page url pathname auth login gt lt a href auth login gt login lt a gt lt div gt lt div class header nav item class active page url pathname auth register gt lt a href auth register gt register lt a gt lt div gt lt div gt lt div gt lt header gt In our CSS there is active class that highlights the active link We used Svelte s class directive to do that e g class active page url pathname auth register Next is Footer lt frontend src lib components Footer svelte gt lt script gt import Developer from lib img hero image png const year new Date getFullYear lt script gt lt footer class footer container gt lt div class footer branding container gt lt div class footer branding gt lt a class footer crafted by container href gt lt span gt Developed by lt span gt lt img class footer branded crafted img src Developer alt John Owolabi Idogun gt lt a gt lt span class footer copyright gt amp copy year John Owolabi Idogun All Rights Reserved lt span gt lt div gt lt div gt lt footer gt Just a basic HTML Back to the layout svelte file We exported a data variable This variable was exported from layout js frontend src routes layout js type import types LayoutLoad export async function load fetch url return fetch url url pathname Next let s build the home page lt frontend src routes page svelte gt lt script gt import Developer from lib img hero image png lt script gt lt div class hero container gt lt div class hero logo gt lt img src Developer alt John Owolabi Idogun gt lt div gt lt h class hero subtitle subtitle gt This application is the demonstration of a series of tutorials on session based authentication using Go at the backend and JavaScript SvelteKit on the front end lt h gt lt div class hero buttons container gt lt a class button dark href data learn more gt Learn more lt a gt lt div gt lt div gt Again just a simple HTML page We also loaded an image in the script tag Our page should look like this now Step User registration pageHaving built out the layout of the pages it s time to look into the user registration page lt frontend src routes auth register page svelte gt lt script gt import applyAction enhance from app forms import receive send from lib utils helpers import scale from svelte transition type import types ActionData export let form type import types SubmitFunction const handleRegister async gt return async result gt await applyAction result lt script gt lt div class container gt lt form class content action register method POST use enhance handleRegister gt lt h class step title title gt Register lt h gt if form errors each form errors as error error id lt h class step subtitle warning in receive key error id out send key error id gt error error lt h gt each if lt div class input box gt lt span class label gt Email lt span gt lt input class input type email name email placeholder Email address gt lt div gt if form fieldsError amp amp form fieldsError email lt p class warning transition scale local start gt form fieldsError email lt p gt if lt div class input box gt lt span class label gt First name lt span gt lt input class input type text name first name placeholder First name gt lt div gt lt div class input box gt lt span class label gt Last name lt span gt lt input class input type text name last name placeholder Last name gt lt div gt lt div class input box gt lt span class label gt Password lt span gt lt input class input type password name password placeholder Password gt lt div gt if form fieldsError amp amp form fieldsError password lt p class warning transition scale local start gt form fieldsError password lt p gt if lt div class input box gt lt span class label gt Confirm password lt span gt lt input class input type password name confirm password placeholder Password gt lt div gt if form fieldsError amp amp form fieldsError confirmPassword lt p class warning transition scale local start gt form fieldsError confirmPassword lt p gt if lt div class btn container gt lt button class button dark gt Register lt button gt lt p gt Already registered lt a href auth login gt Login here lt a gt lt p gt lt div gt lt form gt lt div gt All our authentication related routes will be in the routes auth folder and for the register route it is located in routes auth register page svelte The page looks like this The entire code should look very familiar because it is just HTML However we rely primarily on SvelteKit s form actions which is a preferred way to submit form data to the server The action a NAMED action we will use is the register action and it was specified in the action attribute of our form tag Form actions live in a page server js file in the same folder where page svelte lives This doesn t mean you can t access form actions in a page server js file located in a different route In fact we ll use such an action in this project frontend src routes auth register page server jsimport BASE API URI from lib utils constants import formatError isEmpty isValidEmail isValidPasswordMedium from lib utils helpers import fail redirect from sveltejs kit type import types PageServerLoad export async function load locals redirect user if logged in if locals user throw redirect type import types Actions export const actions param request The request object param fetch Fetch object from sveltekit returns Error data or redirects user to the home page or the previous page register async request fetch gt const formData await request formData const email String formData get email const firstName String formData get first name const lastName String formData get last name const password String formData get password const confirmPassword String formData get confirm password Some validations type Record lt string string gt const fieldsError if isValidEmail email fieldsError email That email address is invalid if isValidPasswordMedium password fieldsError password Password is not valid Password must contain six characters or more and has at least one lowercase and one uppercase alphabetical character or has at least one lowercase and one numeric character or has at least one uppercase and one numeric character if confirmPassword trim password trim fieldsError confirmPassword Password and confirm password do not match if isEmpty fieldsError return fail fieldsError fieldsError const registrationBody email first name firstName last name lastName password type RequestInit const requestInitOptions method POST headers Content Type application json body JSON stringify registrationBody const res await fetch BASE API URI users register requestInitOptions if res ok const response await res json const errors formatError response error return fail errors errors const response await res json throw redirect auth confirming message response message Let s skip the load function for now Our action is one of the keys in the actions object It s an async function that takes in event destructured to retrieve on request fetch in our case Using the request we retrieved the form s data and then individual fields using their names You must set name attributes on each of the form fields as a result thereby conforming to web standards Then we validate the inputs to provide a better user experience This complements the server side validations put in place This means that if a user disables javascript in the browser the backend will catch the mistakes instead The frontend validation logic lives in frontend src lib utils helpers js frontend src lib utils helpers js ts nocheckimport quintOut from svelte easing import crossfade from svelte transition export const send receive crossfade duration d gt Math sqrt d eslint disable next line no unused vars fallback node params const style getComputedStyle node const transform style transform none style transform return duration easing quintOut css t gt transform transform scale t opacity t Validates an email field file lib utils helpers input validation ts param string email The email to validate export const isValidEmail email gt const EMAIL REGEX a z amp a z amp a z a z a z a z a z a z return EMAIL REGEX test email trim Validates a strong password field file lib utils helpers input validation ts param string password The password to validate export const isValidPasswordStrong password gt const strongRegex new RegExp a z A Z amp return strongRegex test password trim Validates a medium password field file lib utils helpers input validation ts param string password The password to validate export const isValidPasswordMedium password gt const mediumRegex new RegExp a z A Z a z A Z return mediumRegex test password trim Test whether or not an object is empty param Record lt string string gt obj The object to test returns true or false export function isEmpty obj for const i in obj return false return true Test whether or not an object is empty param any obj The object to test returns true or false export function formatError obj const errors if typeof obj object amp amp obj null if Array isArray obj obj forEach type Object error gt Object keys error map k gt errors push error error k id Math random else Object keys obj map k gt errors push error obj k id Math random else errors push error obj charAt toUpperCase obj slice id return errors We then make a request to our backend s register endpoint We saved our backend s base URL in a env file lt frontend env gt VITE BASE API URI DEV VITE BASE API URI PROD Your environment variable must start with VITE for vite to pick it up Then in frontend src lib utils constants js we loaded it frontend src lib utils constants jsexport const BASE API URI import meta env DEV import meta env VITE BASE API URI DEV import meta env VITE BASE API URI PROD If there was an error from the backend we properly form it and send it back to the form page Otherwise we move to the confirming route with the response of the backend lt frontend src routes auth confirming page svelte gt lt script gt import page from app stores let message if page url search message page url search split replaceAll lt script gt lt div class container gt lt div class content gt lt h class step title title gt Email sent lt h gt lt h class step subtitle normal gt message lt h gt lt div gt lt div gt You can test the registration form now Step Account activation routeHaving built the registration route we need the complementary route specified in the registration email sent so that users can activate their accounts immediately lt frontend src routes auth activate id page svelte gt lt script gt import applyAction enhance from app forms import page from app stores import receive send from lib utils helpers type import types ActionData export let form type import types SubmitFunction const handleActivate async gt return async result gt await applyAction result type string undefined let token if token token token split join let finalVal token match g join token finalVal lt script gt lt div class container gt lt form class content method POST use enhance handleActivate gt lt h class step title gt Activate your account lt h gt if form errors each form errors as error error id lt h class step subtitle warning in receive key error id out send key error id gt error error lt h gt each if lt input type hidden name user id value page params id gt lt div class input box gt lt span class label gt Token lt span gt lt input type text class input name token placeholder XXX XXX inputmode numeric bind value token maxlength minlength gt lt div gt lt button class button dark gt Activate lt button gt lt form gt lt div gt It is a simple route that looks just like this It simply expects the token sent to such a user Aside from the token it also takes the user s ID as a hidden field Remember that our user activation route requires the user s ID as a path variable Again this page has a complementary page server js file frontend src routes auth activate id page server jsimport BASE API URI from lib utils constants import formatError from lib utils helpers import fail redirect from sveltejs kit type import types PageServerLoad export async function load locals redirect user if logged in if locals user throw redirect type import types Actions export const actions param request The request object returns Error data or redirects user to the home page or the previous page default async request gt const data await request formData const userID String data get user id let token String data get token token token split join type RequestInit const requestInitOptions method PUT headers Content Type application json body JSON stringify token token const res await fetch BASE API URI users activate userID requestInitOptions if res ok const response await res json const errors formatError response error return fail errors errors const response await res json throw redirect auth login message response message The only different things in this code are that we used a default form action here so that we wouldn t specify the action attribute on our HTML form tag Then we used a different backend endpoint and a different HTTP method as expected And lastly we redirected to the login route if the activation is successful Now you should feel pretty proud of yourself to have built this beautiful performant functional and secure system to this point In the next article we ll talk about logging users in and out and retrieving the data of the currently logged in user See ya OutroEnjoyed this article Consider contacting me for a job something worthwhile or buying a coffee You can also connect with follow me on LinkedIn and Twitter It isn t bad if you help share this article for wider coverage I will appreciate it 2023-06-04 12:36:08
海外TECH DEV Community Handling Forms in React https://dev.to/beginarjun/handling-forms-in-react-4i07 Handling Forms in ReactHey there So let me tell you a little story Once upon a time I was trying to learn how to handle forms in React And let me tell you it was not a walk in the park I found myself scratching my head and wondering why on earth it was so difficult to understand But then after many cups of coffee and some late nights it finally clicked And now I want to share my knowledge with all of you lovely people out there who might be struggling just like I was So buckle up and get ready for some form handling fun yes that s a thing Introduction to FormsIn HTML forms are used to collect user s input which is generally sent to a server to process Form can be visualized as a container for all input elements such as text fields radio buttons checkboxes etc You can learn more about forms hereFor example lt form gt lt label for f name gt First name lt label gt lt input type text id f name name f name gt lt label for l name gt Last name lt label gt lt input type text id l name name l name gt lt form gt Need for handling forms In HTML when we submit a form you will notice that the page refreshes itself However since React stores the form data in state If we don t handle forms in React the default behavior of the form will take place i e it will refresh itself and the current state will be lost This means that when the form is submitted the data entered by the user in the form will be lost forever Handling Forms in ReactNow that we know why Handling Form is so important let s get started on how to handle them In React we can handle form using two ways Controlled ComponentsUncontrolled ComponentsLet s see how they differ from each other and their working Controlled ComponentsAn form whose data is being controlled in such a way that it s data is stored in the React state using useState and is updated using setState which can only be triggered by the user To create your own controlled component we need to use the value prop and the onChange prop of the form element For example import useState from react const Form gt To store data in state const data setData useState If you provide a value to the component it must remain a string throughout its lifetime To handle Submit const handleSubmit event gt event preventDefault Prevents the default behaviour alert You have entered the name data To handle change of the input const handleChange event gt setData event target value event preventDefault Prevents the default behaviour return lt form onSubmit handleSubmit gt lt label gt Name lt input type text value data onChange handleChange gt lt label gt lt input type submit value Submit gt lt form gt export default Form Handling Multiple InputsTo handle multiple inputs you can use name attribute of an input element to access it and let the handler function choose what to do with it Note For checkboxes use event target checked instead of event target valueExample import useState from react const Form gt const state setState useState isGoing true numberOfGuests const handleInputChange event gt event preventDefault const target event target const value target type checkbox target checked target value const name target name setState prevState gt return prevState name value console log state return lt form gt lt label gt Is going lt input name isGoing type checkbox checked state isGoing onChange handleInputChange gt lt label gt lt br gt lt label gt Number of guests lt input name numberOfGuests type number value state numberOfGuests onChange handleInputChange gt lt label gt lt form gt export default Form Using controlled components in React can be time consuming because you have to write an event handler for every change in data This can be frustrating when converting old code to React or using it with non React libraries In these cases you might want to try uncontrolled components which are another way to implement forms Uncontrolled ComponentsEven if you manage to create a form which can handle multiple inputs it still wouldn t solve the performance issues as the component would re render after each state update Therefore you may use uncontrolled components which makes use of useRef to get form values from the DOM Document Object Model Example import createRef from react const Form gt const input createRef const handleSubmit event gt event preventDefault alert A name was submitted input current value return lt form onSubmit handleSubmit gt lt label gt Name lt input type text ref input gt lt label gt lt input type submit value Submit gt lt form gt export default FormAs we can see an uncontrolled component gets the form values from the DOM and is much more easier to implement as well as much less code than controlled input However it is still advised to use controlled components instead of uncontrolled components ConclusionYou can head over to all the Sandbox which I ve embedded and try to understand the code more efficiently Also I suggest reading some official docs by React Farewell my brave hobbits 2023-06-04 12:13:13
海外TECH DEV Community Bun vs. Node.js - Benchmarking runtime https://dev.to/refine/bun-vs-nodejs-benchmarking-runtime-4l9b Bun vs Node js Benchmarking runtimeAuthor Victor UmaDo you want to try out a new runtime environment Bun is the new Javascript runtime that claims to be better than Node js This article will show how we can test this with benchmark scores PrerequisitesWhile there is no prerequisite to follow in this tutorial you should at least know the fundamentals of Javascript and building basic web applications You need the followings Node or higherBun runtime installednpm installedA code editor OverviewIn this tutorial we will go over the new Bun runtime that has created a buzz in the tech space lately We will talk about what a runtime does and why some developers are switching over to using bun We will also carry out some benchmark test to see if bun really has the fastest runtime as the Bun team says Let s dive rignt in Steps we ll cover What is a runtimeThe Javascript runtimeWhat is BunWhy is Bun FastInstalling the Bun runtimeHow does Bun compare with NodeBenchmarking Bun What is a runtimeImagine you have a big box of LEGO blocks and you want to build a cool spaceship You have all the instructions on how to put the pieces together but you need something to actually assemble the spaceship and make it work That s where a runtime comes in A runtime is like a special helper that takes care of building and running your LEGO spaceship It s a program that makes sure all the pieces fit together correctly and that the spaceship does what it s supposed to do When you give the instructions to the runtime it reads them step by step and starts putting the LEGO pieces in the right places It follows the instructions precisely making sure each piece is connected properly and that everything is in the right order Once the spaceship is built the runtime also takes care of making it work It powers up the spaceship activates its engines and controls all its cool features It s like a small computer inside the spaceship that runs all the commands and makes sure everything runs smoothly In the world of programming a runtime is similar It s a special program that helps run other programs It reads the instructions of a program executes them step by step and makes sure everything works as intended So just like the helper in assembling the LEGO spaceship a runtime is the special program that helps build and run other programs correctly It s like a smart assistant that makes sure everything works smoothly just like you d expect from your awesome LEGO spaceship The Javascript runtimeThe JavaScript runtime is like a translator between JavaScript and the computer When you tell JavaScript to do something like add two numbers together the runtime listens and understands what you want It then takes that instruction and talks to the computer in a language it understands The runtime also takes care of other important things It makes sure JavaScript follows the rules and doesn t make any mistakes It keeps an eye on JavaScript as it runs like a teacher watching over a student to make sure they re doing their work correctly When the runtime talks to the computer and gets the result it passes it back to JavaScript It s like the runtime whispers the answer to JavaScript and then JavaScript can do something with that answer Maybe it shows the answer on the screen or uses it to make a cool animation What is BunBun is a JavaScript runtime built from scratch using the Zig programming language with a focus on fast startup efficient code execution and a cohesive developer experience It provides tools and features to optimize and streamline the development of JavaScript applications and is designed to be compatible with existing JavaScript ecosystems When you tell Bun what you want it to do it listens carefully It takes your instructions which are written in a special language called JavaScript and starts executing them step by step It s like telling the a car where you want to go and how you want to get there But Bun doesn t just understand JavaScriptーit s also really good at making JavaScript code run really fast It s like having a car engine that can make your car zoom down the road faster than any other car Bun is built using a special programming language called Zig Zig is like a magical tool that allows the people who created Bun to build it in a way that makes it very efficient and fast It s like the secret recipe that makes Bun so powerful With Bun you can do all sorts of things You can build websites and applications that work really quickly and smoothly You can also use the Bun CLI Command Line Interface to run your JavaScript and TypeScript files bundle your code together and even manage your project s dependencies Why is Bun FastThe Bun runtime exhibits impressive speed due to several key factors Lightweight Design Bun is designed to be lightweight resulting in a smaller codebase and reduced resource requirements This optimized design allows Bun to deliver better performance in terms of both speed and memory usage compared to other runtimes Low Level Implementation The Bun runtime is built using Zig a relatively new low level programming language Zig s characteristics enable developers to write code with fine grained control over memory management and execution contributing to the runtime s efficiency Performance Optimization Instead of relying on the V engine Bun utilizes the JavaScriptCore from WebKit which is widely recognized for its superior performance By leveraging this core engine Bun benefits from its optimized execution of JavaScript code resulting in improved runtime speed Integrated Functionality Bun offers native tools and features that streamline the development process It includes a built in bundler replacing the need for external tools like Webpack as well as a native transpiler that supports writing TypeScript code directly Additionally Bun incorporates a test runner similar to Jest and automatically loads environment variables without requiring additional installations of packages like dotenv Installing the Bun runtimeTo install Bun you can follow these steps Open your computer s terminal or command prompt In the terminal enter the following command curl fsSL https bun sh install bashFor macOS users run this after exec bin zshThis command will initiate the installation process for Bun by downloading the installation script from the official Bun website Press Enter and allow the installation script to run It will handle the necessary steps to install Bun and its dependencies on your system Wait for the installation process to complete The script will take care of all the required tasks to ensure Bun is properly installed on your computer Once the installation is finished you will have successfully installed Bun You can now start using the Bun runtime to run your JavaScript and TypeScript applications and take advantage of its bundled tools and optimized performance How does Bun compare with NodeIn this section we ll look at how Bun compares to Node and do some benchmarking between this two runtime Language Support While Node js supports a broad range of programming languages including JavaScript and its variants like TypeScript Bun primarily focuses on JavaScript and TypeScript Performance Bun emphasizes faster startup times and runtime performance by utilizing the JavaScriptCore engine from WebKit renowned for its speed In contrast Node js relies on the V engine which is also highly optimized but may have performance distinctions compared to JavaScriptCore Size and Dependencies Bun strives to be a lightweight runtime with a smaller codebase and minimal dependencies It incorporates built in tools like a bundler and transpiler reducing reliance on external dependencies In contrast Node js is a more comprehensive runtime with a larger codebase and extensive support for external modules and libraries Compatibility Although Bun aims to serve as a drop in replacement for Node js there may be variances in API compatibility While Bun natively implements many Node js and Web APIs some specific Node js modules or APIs might not be fully supported Tooling Bun provides an integrated toolkit for JavaScript development including a bundler transpiler and package manager Node js on the other hand boasts a rich ecosystem of third party tools and libraries for diverse development tasks such as popular bundlers like Webpack and package managers like npm or Yarn Community and Ecosystem Node js benefits from a mature and extensive community offering substantial support well documented resources and a vast ecosystem of modules and libraries In contrast Bun being relatively newer may have a smaller community and a more focused ecosystem Open source enterprise application platform for serious web developersrefine new enables you to create React based headless UI enterprise applications within your browser that you can preview tweak and download instantly By visually combining options for your preferred React platform UI framework backend connector and auth provider you can create tailor made architectures for your project in seconds It feels like having access to thousands of project templates at your fingertips allowing you to choose the one that best suits your needs Benchmarking BunThis benchmarking test is running on my Mac M gb ram computer For the benchmarking tool we will be using k an open source tool by Grafana labs You can find the installation guide for this tool here Here is our computer software version Node v Bun v For our code I have gotten a simple HTTP server code from the Bun and Node js official sites Here is the Hello World code in Bun and NodeNodeconst http require http const hostname const port const server http createServer req res gt res statusCode res setHeader Content Type text plain res end Hello World server listen port hostname gt console log Server running at http hostname port Run the command in your terminal node server jsYour node server will be running on port http localhost Bunexport default port fetch return new Response Hello World Your Bun server will be running on port http localhost Run the command in your terminal bun run bunserver jsCreate a script js file and paste this test script import http from k http import sleep from k export default function http get http localhost this will change depending on the server you re testing for sleep In your terminal run k run script jsHere is the result for our Node server Here is the result for our Bun server We can now see and compare Bun speed to Node If you want to go further you can introduce different latencies more users and duration with the script k run vus duration s script js ConclusionIn conclusion Bun and Node js are two JavaScript runtimes that offer different approaches and features for developers Bun focuses on delivering fast startup times optimized performance and a lightweight design with integrated tools like a bundler and transpiler It utilizes the JavaScriptCore engine from WebKit to achieve its performance goals On the other hand Node js has a larger ecosystem extensive community support and compatibility with a wide range of programming languages It relies on the V engine and offers a rich set of third party tools and libraries Choosing between Bun and Node js depends on factors such as performance requirements specific project needs and the availability of suitable tooling and community support Ultimately developers can leverage the strengths of each runtime to build robust and efficient JavaScript applications 2023-06-04 12:11:42
ニュース BBC News - Home Fair for asylum seekers to share hotel rooms, says Robert Jenrick https://www.bbc.co.uk/news/uk-politics-65802335?at_medium=RSS&at_campaign=KARANGA asylum 2023-06-04 12:33:27
ニュース BBC News - Home Bournemouth beach deaths: Funeral held for girl pulled from sea https://www.bbc.co.uk/news/uk-england-dorset-65802673?at_medium=RSS&at_campaign=KARANGA bournemouth 2023-06-04 12:05:51
ニュース BBC News - Home Man arrested at Wembley over '97' football shirt https://www.bbc.co.uk/news/uk-england-65800061?at_medium=RSS&at_campaign=KARANGA hillsborough 2023-06-04 12:31:25
ニュース BBC News - Home FA Cup final: Elton John bumps into Manchester City players at airport https://www.bbc.co.uk/sport/av/football/65803779?at_medium=RSS&at_campaign=KARANGA FA Cup final Elton John bumps into Manchester City players at airportWatch as Manchester City players bump into Elton John at the airport after their FA Cup final victory over Manchester United at Wembley 2023-06-04 12:02:54

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)