The following Next.js example uses the path segment in its functionality when requested:
export default function handler(req, res) {
const { name } = req.query;
res.end(`Hello ${name}!`);
}
paths: | |
/graphql: | |
post: | |
summary: 'My GraphQL API Endpoint' | |
description: 'My GraphQL API Endpoint' | |
operationId: 'graphql' | |
responses: | |
'200': | |
description: 'Successfull Query' | |
content: |
// https://nodejs.org/api/stream.html#api-for-stream-consumers | |
const http = require('http'); | |
const server = http.createServer((req, res) => { | |
// `req` is an http.IncomingMessage, which is a readable stream. | |
// `res` is an http.ServerResponse, which is a writable stream. | |
let body = ''; | |
// Get the data as utf8 strings. |
const express = require('express') | |
const app = express() | |
const port = 3000 | |
app.get('/', (req, res) => { | |
res.sendFile(__dirname + '/index.html'); | |
}); | |
app.listen(port, () => { | |
console.log(`Example app listening at http://localhost:${port}`) |
// npx | |
console.log("Hello World") |
A brief example on how to use npx
to run gist based scripts.
Read the article here https://neutrondev.com/npm-vs-npx-whats-the-difference/ or watch it on YouTube https://www.youtube.com/watch?v=fSHWc8RTJug
Create a new file named seed.js. This can be placed anywhere within your projects folder structure. The below example places it in the /prisma folder.
In the seed.js file, import Prisma Client, initialize it and create some records.
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
async function main() {
const alice = await prisma.user.upsert({
React is the entry point to the React library.
import React from 'react'
var React = require('react')
<script>
tag, these top-level APIs are available on the React global:<script crossorigin src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
https://runkit.com/docs/endpoint
exports.endpoint = function(request, response) {
response.end("Hello world!");
}
//https://nodejs.org/docs/v0.10.40/api/http.html#http_event_upgrade_1 | |
var http = require('http'); | |
// Create an HTTP server | |
var srv = http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('okay'); | |
}); | |
srv.on('upgrade', function(req, socket, head) { | |
socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + |