npm-packages/docs/docs/quickstart/nodejs.mdx
import sampleData from "!!raw-loader!@site/../private-demos/quickstarts/nodejs/sampleData.jsonl"; import tasks from "!!raw-loader!@site/../private-demos/quickstarts/nodejs/convex/tasks.js"; import script from "!!raw-loader!@site/../private-demos/quickstarts/nodejs/script.js";
Learn how to query data from Convex in a Node.js project.
For instructions for subscriptions instead of point-in-time queries and more project configurations (TypeScript, bundlers, CJS vs ESM) see Node.js notes.
<StepByStep> <Step title="Create a new npm project"> Create a new directory for your Node.js project.```sh
mkdir my-project && cd my-project && npm init -y && npm pkg set type="module"
```
Also install the `dotenv` library for loading `.env` files.
```sh
npm install convex dotenv
```
It will also create a `convex/` folder for you
to write your backend API functions in. The `dev` command
will then continue running to sync your functions
with your dev deployment in the cloud.
```sh
npx convex dev
```
<Snippet
source={sampleData}
title="sampleData.jsonl"
/>
```
npx convex import --table tasks sampleData.jsonl
```
Exporting a query function from this file
declares an API function named after the file
and the export name, `api.tasks.get`.
<Snippet
source={tasks}
title="convex/tasks.js"
/>
<Snippet
source={script}
title="script.js"
/>
```sh
node script.js
```
See the complete Node.js documentation.