js |
JavaScriptタグが付けられた新着投稿 - Qiita |
[JS]繰り返しの処理 |
https://qiita.com/Shi-raCanth/items/d8a04310f99abc3a44df
|
構文は以下の通りfor①初期化式②条件式③加算式繰り返す処理の内容例forletiilti回処理を繰り返す①初期化式initializationfor文の中で使用する変数を定義する。 |
2022-01-22 23:57:47 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
素のJSでQiitaAPIを叩く(Ajax) |
https://qiita.com/hiramiya/items/3b7d28784ffaf5a6edf9
|
素のJSでQiitaAPIを叩くAjaxAjaxとAPIの学習用ソース書く前に取得できるかcurlコマンドで確認。 |
2022-01-22 23:43:31 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
3行3列の行列の固有値の代数的求解 |
https://qiita.com/norimy/items/88f119fa4e59efeb4179
|
この時、固有値を求める方程式はlambdaboldsymbolIboldsymbolAとなります。 |
2022-01-22 23:30:03 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
Nuxt3、Vue3、Firebase V9をDocker上で環境構築 |
https://qiita.com/sho_U/items/49100103c7165fb5c789
|
コンテナ内npminstallローカルサーバを立ち上げて確認するコンテナ内npmrundevhttplocalhostにアクセスして下記のページが表示されていたら成功※dockercomposeymlの下記の記述によりホストのローカルホストポートからコンテナ内のサーバーポートにアクセスしています。 |
2022-01-22 23:34:07 |
Azure |
Azureタグが付けられた新着投稿 - Qiita |
OpenHack for Modern Data Warehousing で得た気づき ~初学者でも怖くないよ!~ |
https://qiita.com/hanaseleb/items/d6b5c170d380c37421c2
|
毎回テーマが変わり、今回はModernDataWarehousingがテーマでした。 |
2022-01-22 23:25:27 |
Git |
Gitタグが付けられた新着投稿 - Qiita |
ターミナルで「git log」入力後にキーボードが反応しなくなったら |
https://qiita.com/meri96bockn/items/82e3f6c3c7a3fac6b0dd
|
gitlog |
2022-01-22 23:05:47 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
[JS]繰り返しの処理 |
https://qiita.com/Shi-raCanth/items/d8a04310f99abc3a44df
|
構文は以下の通りfor①初期化式②条件式③加算式繰り返す処理の内容例forletiilti回処理を繰り返す①初期化式initializationfor文の中で使用する変数を定義する。 |
2022-01-22 23:57:47 |
技術ブログ |
Developers.IO |
Google Tag ManagerでDOM要素の表示を条件にしてタグ配信する |
https://dev.classmethod.jp/articles/distribute-tags-based-on-the-display-of-dom-elements-in-google-tag-manager/
|
googletagmanager |
2022-01-22 14:54:34 |
海外TECH |
MakeUseOf |
3 Things You Can Do With Opera's New Crypto Browser |
https://www.makeuseof.com/opera-crypto-browser-features/
|
browser |
2022-01-22 14:36:01 |
海外TECH |
MakeUseOf |
What Is the Blister Malware? Tips to Stay Protected |
https://www.makeuseof.com/what-is-blister-malware/
|
blister |
2022-01-22 14:30:44 |
海外TECH |
MakeUseOf |
How to Buy Virtual Land in the Metaverse |
https://www.makeuseof.com/how-to-buy-virtual-land-in-the-metaverse/
|
virtual |
2022-01-22 14:00:43 |
海外TECH |
DEV Community |
A Curated List of Resource to Build Website and Apps Without Code! |
https://dev.to/ieeemace/a-curated-list-of-resource-to-build-website-and-apps-without-code-607
|
A Curated List of Resource to Build Website and Apps Without Code Are you a beginner to programming or do you want to build a website or an App without learning to code or NO CODE Here are some list of platforms available to build responsive websites and applicationsWeb development without Coding Bootstrap studioLink Bootstrap Studio is an app for creating beautiful websites It comes with a large number of built in components which you can drag and drop to assemble responsive web pages It is built on top of the hugely popular Bootstrap framework and exports clean and semantic HTML If you need a component which doesn t exist in our library just click the Online tab in the Component Panel There you will find thousands of components built and shared by the community You can also upload your own If you have a website that you ve developed previously you can import it Just drag and drop the HTML CSS JS files and images into Bootstrap Studio and they will be added to your project BravostudioLink Bravo Studio is an app builder for designers It makes it possible to turn Figma prototypes into native iOS and Android app instantly without writing any code Quest ai Link Convert your designs into responsive live websites automatically Add interactions motion graphics video audio without writing any code Connect to data and content source and build fully functioning websites landing pages product pages or business applications easily With Quest anyone can build what they envision without being constrained by their engineering bandwidth Wix website builder Link Wix is totally beginner friendly Wix is a free web based website builder based You can build responsive website just by drag and drop feature so you don t need coding skills Free version has all the tools you need for development And you have thousands of templates of different category to begin with There are many modules that you can add on in the wix store and you can publish the website for free though wix will be added in the domain address in the free version And there are build in option for search engine optimisation WebflowLink With Webflow you can build a prototype that is already a finished product How cool is that Webflow is a powerful web based design tool that gives you the superpower of designing building and launching responsive websites without the use of code It s an all star level design platform that allows you to go from the initial idea to ready to use products It fills the gap between software like Squarespace Wix and the world s most popular CMS WordPress Webflow s design flexibility lightning speed performance and ease of use make it quite a success story as I find Webflow referred to as the next generation tool for building and launching websites by newcomers and professionals across the web App development without Coding In the past you had to be a programmer to make an app which would likely take weeks months or even years Now however there are numerous app building platforms you can use to create an app in minutes We ve put together some of our favorites for you here MIT App Inventor Link MIT App Inventor is great for beginners The layout is visual and relies on drag and drop which helps users understand the components needed for an app It also clearly has features of Android programming in Java which makes the transition to written code for Android easier AppyPie link AppyPie has helped more than million creators to build a fully functional mobile app with nothing but visual building blocks On top of support for Android and iOS AppyPie also offers full on PWA Progressive Web Apps functionality So your mobile app will be viewable in a web browser like a regular website This pretty much solves two issues at the same time Adalo Link Adalo helps you design new apps without any coding skills You will be capable of completely controlling your design by using drag and drop components With Adalo you have the freedom to add database configuration and interactions automatically If you have an existing API then Adalo will integrate with the same With a single click you will be able to launch the true version of your mobile apps on the application stores for Android and iOS In conclusion know what features you re looking for in your mobile Web application This will help you narrow down the platforms which can best serve your needs And that concludes our list Happy Building ️Website Instagram LinkedIn Twitter |
2022-01-22 14:10:59 |
海外TECH |
DEV Community |
How to build a REST API using NodeJS |
https://dev.to/kira272921/how-to-build-a-rest-api-using-nodejs-19ai
|
How to build a REST API using NodeJSHey everyone I know it s been a long since I posted a new blog So in this blog post we are doing to build a REST API that would serve as a source of motivation for developers using NodeJS and MongoDB So let s get started ️ What s an API API stands for Application Programming Interface which is a tool that allows two applications to talk to each other Let s understand the meaning of API by some real life examples So you have built an amazing e store application and you wanted other developers to build applications on it Now you have to build some sort of software that communicates between your web service and the developer s application and that s where API comes in What s a REST API Now as you have let s talk something about REST APIs REST stands for Representational State Transfer it s one of the most popularly known type of API architecture These types of APIs follow the client server model where one program sends a request and the other response with some data The requests are HTTP methods such as POST GET PUT DELETE You would have a more clear understanding of APIs and REST APIs when we build a project So what are we waiting for let s dive started into coding Setting up the project Let s set up our project so that we can start coding Creating a separate folder for our project mkdir dev credits apiNavigate into the folder cd dev credits apiInitializing the project npm initInstalling the required packages npm install mongoose express dotenv cors or yarn add mongoose express dotenv corsExpress is the framework by which we are going to our REST APIMongoose is the tool that we are going to use to communicate with our MongoDB database Installing nodemon as a dev dependency npm install nodemon D or yarn add nodemon DNodemon is used for automatically restarting the server on file changes detected in the directory This would be helpful as we would not be restarting the server each time we do changes Building the REST API As we have completed the setup for our project let s get started building the REST API Create a new file named index jsHere is the boilerplate code for a basic express appindex jsconst express require express const app express const port process env PORT app listen port async gt console log Server is running at port port Let s breakdown it into and understand each part We are requiring the express package into our file so that we can use itWe are assigning some value to the variable port the port where our server would be running You might be thinking why is there a process env PORT It s because during deployment on services such as Heroku the port number might vary it may not be so we are telling that if there is a PORT environment variable then use that else use The last piece of code is telling to which port the server should listen in our case it s the PORT variableLet s add a new script named start to the package json file which uses nodemon to automatically restart the server on file changes detected So after the changes our scripts in package json would look something like this scripts start nodemon index js Let s start our server by running the npm start command The server would be running at http localhost You prompted with an error something like this This is happening because we haven t defined the aka the root route HTTP methods explainedLet s take a break from coding and understand what do they do and what s the success and error status so that it would be easy for debugging GETWhat it does Request data from a specified resourceSuccessful response OKError response not found POSTWhat it does Send data to the server to create a new resourceSuccessful response CreatedError response not found or conflict if the resource already exists PUTWhat it does Send data to the server to update a pre existing resourceSuccessful response OKError response no content not found or method not allowed DELETEWhat it does Deletes a resource from the serverSuccessful response OKError response not found or method not allowedCheck out http cat for understanding what each HTTP status code means via funny cat images Adding routes Routes are different URL paths of an express app that are associated with different HTTP methods such as GET POST DELETE PUT Let s get started by creating which sends Hello World Add the below piece of code above the line where we declared the port variableindex jsapp get function req res res send Hello World Let s breakdown this piece of code The get method specifies the HTTP method for that route You could use other HTTP methods like post delete There is a special routing method all which is used for the routes which handle all kinds of HTTP methodsThere is a callback method that is called when the server receives a request from that endpoint with that specified HTTP methodHorray Hello World is now visible in the route Setting up MongoDBLet s get in the MongoDB database now Head over MongoDB and sign up sign in and create a new projectYou could your co worker into the project if you wanted too After the creation of the project click on Build a DatabaseYou would be shown with a screen something like this Let s go ahead and choose the free plan You would be shown some more options about the cloud provider and the locationLet s choose the nearest region and move forward You would be asked to create a user This is required as you would need the username and password to generate a connection URL which is then used to connect MongoDB with your NodeJS app The creation of the cluster would take minutes So let s grab a cup of coffee until then Ahh it s been successfully created so let s get back to coding Click on ConnectClick on Connect your applicationCopy the connection URLCreate a env file and replace lt password gt with the password of the user which you have replaced previouslyMONGODB URL mongodb srv kira lt password gt dev credits api ttkf mongodb net myFirstDatabase retryWrites true amp w majority Let s head back to the good old index js file Connecting Express app to MongoDBLet s start by requiring mongoose and dotenvconst mongoose require mongoose const dotenv require dotenv Let s configure dotenv as welldotenv config Let s finally add the piece of code which connects our express application to MongoDBmongoose connect process env MONGODB URL useNewUrlParser true useUnifiedTopology true then gt console log Connected to MongoDB catch err gt console log err The index js file show looks something like this nowindex jsconst express require express const mongoose require mongoose const dotenv require dotenv dotenv config const app express mongoose connect process env MONGODB URL useNewUrlParser true useUnifiedTopology true then gt console log Connected to MongoDB catch err gt console log err app get function req res res send Hello World const port process env PORT app listen port async gt console log Server is running at port port We successfully connected our express app to the MongoDB database Creating Schema and Model A Schema is the structure of the documents in our database It tells what fields are required what s the data type of each field A model provides a programming interface for interacting with the database read insert update etc Let s create a new folder named model and inside it let s create a model js where we will define our schemamodel model jsconst mongoose require mongoose const devCredits new mongoose Schema credits type Number required true id type Number required true module exports mongoose model devCredits devCredits Let s breakdown it down and understandWe imported the mongoose package into the model model js fileWe created a new schema named devCredits The structure has the credits and id Credits are the number of dev credits the person has and the id is the discord id of the user This API was initially created for a discord bot Dev credits bot so the schema of the database is kinda based on discord ️ We have finally created a model named devCredits Adding more features Let s add more routes to our REST API Let s add routes where we can get the total dev credits of a user via their discord ID and give dev credits to other users using another route Giving dev credits to other devsLet s import our model which we have just created into the index js file const devCredits require model model js Let s add a new POST route in the index js fileapp post post function req res const credit new devCredits id req body id credits req body credits devCredits countDocuments id req body id function err count if count gt devCredits findOneAndUpdate id req body id inc credits req body credits new true err devCredit gt if err res send err else res json devCredit else credit save err credits gt if err res send err res json credits Let s understand what exactly is going on We have created a new POST route post We validate the data which we receive from the client using our modelIn the next piece of code we are checking if the user user id already exists in the database or notIf exists then we are going to increment the credits valueElse we are going to create a new document with the user id and add the credits How to test the API We have successfully created added a new feature in our API But wait how are we going to test it out We are going to use a VSCode extension called Thunder Client which is used for API testing So let s quickly download it and test our new feature in our API After the completion of the download you are going to see a thunder icon in your sidebar Click the thunder icon and you are going to see a section something like thisClick on New Request You would be prompted to screen something like thisLet s test out our post route now Change the URL in the input box from to HTTP localhost postChange the HTTP method from GET to POSTNavigate to the Body tab this is the section where we are going to write the body of the request I have added my discord ID and gave dev credits to it cuz why notLet s click and hope that it works and we got an errorThis happened because we didn t have any middleware so let s them quicklyindex jsapp use cors app use express json app use express urlencoded extended false NOTE We had installed cors as a separated package so don t forget to import it as wellLet s try again now so that it works now TADA We have successfully created our first feature in the API which interacts with the MongoDB database Getting the total dev credits of a userLet s import our model which we have just created into the index js file const devCredits require model model js Let s add a new route in the index js fileapp get get id function req res devCredits find id req params id id v err data gt if err res json err res json data Let s breakdown this downWe have created a new route with the GET methodWe are finding in the database for the ID given in the parametersLet s test it out again using Thunder Client TADA It s works Cleaning up the codebaseLet s clean up the codebase a bit Let s create a new folder called routes and inside it let s create a new file router js which contains the routesroutes router jsconst router require express Router const devCredits require model model js router get get id function req res devCredits find id req params id id v err data gt if err res json err res json data router post post function req res const credit new devCredits id req body id credits req body credits devCredits countDocuments id req body id function err count if count gt devCredits findOneAndUpdate id req body id inc credits req body credits new true err devCredit gt if err res send err else res json devCredit else credit save err credits gt if err res send err res json credits module exports router We have imported the routes router js file into the index js file and used itindex jsconst express require express const mongoose require mongoose const dotenv require dotenv const cors require cors dotenv config const router require routes router js const app express app use cors app use express json app use express urlencoded extended false mongoose connect process env MONGODB URL useNewUrlParser true useUnifiedTopology true then gt console log Connected to MongoDB catch err gt console log err app get function req res res send Hello World app use router const port process env PORT app listen port async gt console log Server is running at port port Let s test it out so that we are sure that our code and we didn t mess up by cleaning up the mess Horray There isn t any error and the code still works as it was beforeDoesn t routes router js seem kinda filled up with the logic and make it kinda messy Let s create a new folder named controllers In this folder we will store the logic related to each route Let s get started by creating a new file in the controllers folder named getCredits js and postCredits js which contains the logic related to the get route and post route respectivelycontrollers getCredits jsconst devCredits require model model js const getCredits req res gt devCredits find id req params id id v err data gt if err res json err res json data module exports getCredits controllers postCredits jsconst devCredits require model model js const postCredits req res gt const credit new devCredits id req body id credits req body credits devCredits countDocuments id req body id function err count if count gt devCredits findOneAndUpdate id req body id inc credits req body credits new true err devCredit gt if err res send err else res json devCredit else credit save err image gt if err res send err res json image module exports postCredits routes router jsconst router require express Router const devCredits require model model js const getCredits require controllers getCredits js const postCredits require controllers postCredits js router get get id getCredits router post post postCredits module exports router Phew that was a lot of work Adding rate limitYou don t want some random guy to just spam your entire database So let s add a rate limit to our API when restricts the client to perform only a few requests every x minutesLet s install express rate limit package npm install express rate limit or yarn add express rate limitLet s create a middleware folder that contains all the middlewares of our API Create a file named rateLimiter js under the middleware foldermiddleware rateLimiter jsconst rateLimit require express rate limit const rateLimiter rateLimit windowMs minute max message Bonk module exports rateLimiter Let s understand what this piece of code is doing We are importing the express rate limit packageThe windowMs specifies the durationThe max specifies the max amount of requests the client can make in the duration specifiedThe message is the message which is shown to the client when he exceeds the max limitSo let s import into the index js file and test it outindex jsconst rateLimiter require middleware rateLimiter js app use rateLimiter I got bonked by myself Deploying our API on HerokuWe have successfully built an API but how would other developers use it if it isn t deployed Let s deploy it on Heroku Get started by initializing a git repository in the directory Create a new GitHub repository and push your changes into that repository Let s create a new file named Procfile which is just a file that tells Heroku which command is need to be run Add the below content to the Procfile fileweb node index jsNOTE nodemon doesn t work in the production stage It only works in the development stage so we have to use the good old node index jsCreate an account on Heroku and click on Create new app give some cool name to your APIHead over to the settings tab and click Reveal Config VarsThese are the environment variablesAdd a new config var with the key as MONGODB URL and the value as your MongoDB connection URLHead back to the deploy tab and connect the GitHub repository which you have created just before to your Heroku applicationClick the Deploy branch button TADA You have successfully created a REST API and deployed it as well DThe entire source code for this tutorial will be available on my GitHub Check out the API which we built today That s it for this blog folks Meet y all in the next blog post |
2022-01-22 14:08:57 |
Apple |
AppleInsider - Frontpage News |
Best deals Jan. 22: $850 12.9-inch iPad Pro, $425 off Roomba combo, more! |
https://appleinsider.com/articles/22/01/22/best-deals-jan-22-850-129-inch-ipad-pro-425-off-roomba-combo-more?utm_medium=rss
|
Best deals Jan inch iPad Pro off Roomba combo more Saturday s best deals include a inch iPad Pro for a TB Seagate hard drive for and a LePow portable monitor for Best Deals for January As we do every day we ve collected some of the best deals we could find on Apple products tech accessories and other items for the AppleInsider audience If an item is out of stock it may still be able to be ordered for delivery at a later date Read more |
2022-01-22 14:26:31 |
海外科学 |
NYT > Science |
Their DNA Hides a Warning, but They Don’t Want to Know What It Says |
https://www.nytimes.com/2022/01/21/health/dna-biobanks-mutations.html
|
Their DNA Hides a Warning but They Don t Want to Know What It SaysSome volunteers for biobanks which collect genetic information to study health across populations have been surprised to be informed they carry risky mutations |
2022-01-22 14:14:00 |
ニュース |
BBC News - Home |
Everton lose to Villa in Ferguson's first game since Benitez sacking |
https://www.bbc.co.uk/sport/football/60005894?at_medium=RSS&at_campaign=KARANGA
|
Everton lose to Villa in Ferguson x s first game since Benitez sackingEmiliano Buendia scores the winner for Aston Villa as Duncan Ferguson s second spell in interim charge of Everton begins with defeat at Goodison Park |
2022-01-22 14:53:14 |
ニュース |
BBC News - Home |
'I don't know if dreams are made better' - Ryding claims Britain's first World Cup alpine skiing gold |
https://www.bbc.co.uk/sport/winter-sports/60097540?at_medium=RSS&at_campaign=KARANGA
|
x I don x t know if dreams are made better x Ryding claims Britain x s first World Cup alpine skiing goldDave Ryding wins Britain s first alpine skiing World Cup gold medal with victory in the Kitzbuhel Slalom |
2022-01-22 14:33:13 |
ニュース |
BBC News - Home |
Australian Open: Watch the best shots as Dan Evans loses to Felix Auger-Aliassime |
https://www.bbc.co.uk/sport/av/tennis/60096885?at_medium=RSS&at_campaign=KARANGA
|
Australian Open Watch the best shots as Dan Evans loses to Felix Auger AliassimeWatch the best shots as Dan Evans is defeated by ninth seed Felix Auger Aliassime at the Australian Open a result which ended British interest in the singles |
2022-01-22 14:29:24 |
北海道 |
北海道新聞 |
ドイツ最大野党党首にメルツ氏 メルケル氏活躍の保守勢力 |
https://www.hokkaido-np.co.jp/article/636676/
|
最大野党 |
2022-01-22 23:12:00 |
コメント
コメントを投稿